Skip to content

Commit

Permalink
fix(bridge): avoid LinkByName netlink calls
Browse files Browse the repository at this point in the history
Main reason is perfoamnce.
If we have the relevant info in the cache/DB,
we could just use it instead of netlink get calls.

Fixes #123

Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Aug 31, 2023
1 parent 1a2b0e5 commit b6abdeb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
7 changes: 1 addition & 6 deletions pkg/evpn/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ func (s *Server) CreateLogicalBridge(_ context.Context, in *pb.CreateLogicalBrid
}
// create vxlan only if VNI is not empty
if in.LogicalBridge.Spec.Vni != nil {
bridge, err := s.nLink.LinkByName(tenantbridgeName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", tenantbridgeName)
log.Printf("error: %v", err)
return nil, err
}
// Example: ip link add vxlan-<LB-vlan-id> type vxlan id <LB-vni> local <vtep-ip> dstport 4789 nolearning proxy
myip := make(net.IP, 4)
// TODO: remove hard-coded 167772162 == "10.0.0.2"
Expand All @@ -79,6 +73,7 @@ func (s *Server) CreateLogicalBridge(_ context.Context, in *pb.CreateLogicalBrid
return nil, err
}
// Example: ip link set vxlan-<LB-vlan-id> master br-tenant addrgenmode none
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
if err := s.nLink.LinkSetMaster(vxlan, bridge); err != nil {
fmt.Printf("Failed to add Vxlan to bridge: %v", err)
return nil, err
Expand Down
7 changes: 1 addition & 6 deletions pkg/evpn/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ func (s *Server) CreateSvi(_ context.Context, in *pb.CreateSviRequest) (*pb.Svi,
return nil, err
}
// not found, so create a new one
bridge, err := s.nLink.LinkByName(tenantbridgeName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", tenantbridgeName)
log.Printf("error: %v", err)
return nil, err
}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
vid := uint16(bridgeObject.Spec.VlanId)
// Example: bridge vlan add dev br-tenant vid <vlan-id> self
if err := s.nLink.BridgeVlanAdd(bridge, vid, false, false, true, false); err != nil {
Expand Down
7 changes: 1 addition & 6 deletions pkg/evpn/vrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,8 @@ func (s *Server) DeleteVrf(_ context.Context, in *pb.DeleteVrfRequest) (*emptypb
}
// use netlink to find BRIDGE device
bridgeName := fmt.Sprintf("br%d", *obj.Spec.Vni)
bridgedev, err := s.nLink.LinkByName(bridgeName)
bridgedev := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: bridgeName}}
log.Printf("Deleting BRIDGE %v", bridgedev)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", bridgeName)
log.Printf("error: %v", err)
return nil, err
}
// bring link down
if err := s.nLink.LinkSetDown(bridgedev); err != nil {
fmt.Printf("Failed to up link: %v", err)
Expand Down

0 comments on commit b6abdeb

Please sign in to comment.