Skip to content

Commit

Permalink
refactor(svi): move netlink to a separate file
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Oct 17, 2023
1 parent 38f466d commit eb4f214
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
39 changes: 8 additions & 31 deletions pkg/evpn/svi.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,49 +93,26 @@ func (s *Server) DeleteSvi(ctx context.Context, in *pb.DeleteSviRequest) (*empty
err := status.Errorf(codes.NotFound, "unable to find key %s", in.Name)
return nil, err
}
// use netlink to find br-tenant
bridge, err := s.nLink.LinkByName(ctx, tenantbridgeName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", tenantbridgeName)
return nil, err
}
// use netlink to find VlanId from LogicalBridge object
// fetch object from the database
bridgeObject, ok := s.Bridges[obj.Spec.LogicalBridge]
if !ok {
err := status.Errorf(codes.NotFound, "unable to find key %s", obj.Spec.LogicalBridge)
return nil, err
}
vid := uint16(bridgeObject.Spec.VlanId)
// Example: bridge vlan del dev br-tenant vid <vlan-id> self
if err := s.nLink.BridgeVlanDel(ctx, bridge, vid, false, false, true, false); err != nil {
fmt.Printf("Failed to del vlan to bridge: %v", err)
return nil, err
}
vlanName := fmt.Sprintf("vlan%d", vid)
vlandev, err := s.nLink.LinkByName(ctx, vlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", vlanName)
return nil, err
}
log.Printf("Deleting VLAN %v", vlandev)
// bring link down
if err := s.nLink.LinkSetDown(ctx, vlandev); err != nil {
fmt.Printf("Failed to up link: %v", err)
return nil, err
}
// use netlink to delete vlan
if err := s.nLink.LinkDel(ctx, vlandev); err != nil {
fmt.Printf("Failed to delete link: %v", err)
return nil, err
}
// fetch object from the database
vrf, ok := s.Vrfs[obj.Spec.Vrf]
if !ok {
err := status.Errorf(codes.NotFound, "unable to find key %s", obj.Spec.Vrf)
return nil, err
}
vrfName := path.Base(vrf.Name)
// configure netlink
if err := s.netlinkDeleteSvi(ctx, in, bridgeObject, vrf); err != nil {
return nil, err
}
// delete from FRR
vrfName := path.Base(vrf.Name)
vid := uint16(bridgeObject.Spec.VlanId)
vlanName := fmt.Sprintf("vlan%d", vid)
if err := s.frrDeleteSviRequest(ctx, obj, vrfName, vlanName); err != nil {
return nil, err
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/evpn/svi_netlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,36 @@ func (s *Server) netlinkCreateSvi(ctx context.Context, in *pb.CreateSviRequest,
}
return nil
}

func (s *Server) netlinkDeleteSvi(ctx context.Context, _ *pb.DeleteSviRequest, bridgeObject *pb.LogicalBridge, _ *pb.Vrf) error {
// use netlink to find br-tenant
bridge, err := s.nLink.LinkByName(ctx, tenantbridgeName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", tenantbridgeName)
return err
}
vid := uint16(bridgeObject.Spec.VlanId)
// Example: bridge vlan del dev br-tenant vid <vlan-id> self
if err := s.nLink.BridgeVlanDel(ctx, bridge, vid, false, false, true, false); err != nil {
fmt.Printf("Failed to del vlan to bridge: %v", err)
return err
}
vlanName := fmt.Sprintf("vlan%d", vid)
vlandev, err := s.nLink.LinkByName(ctx, vlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", vlanName)
return err
}
log.Printf("Deleting VLAN %v", vlandev)
// bring link down
if err := s.nLink.LinkSetDown(ctx, vlandev); err != nil {
fmt.Printf("Failed to up link: %v", err)
return err
}
// use netlink to delete vlan
if err := s.nLink.LinkDel(ctx, vlandev); err != nil {
fmt.Printf("Failed to delete link: %v", err)
return err
}
return nil
}

0 comments on commit eb4f214

Please sign in to comment.