Skip to content

Commit

Permalink
feat(bridge): decouple linux devname from object resource id
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 Aug 30, 2023
1 parent 0ae986a commit e21063e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions pkg/evpn/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (s *Server) CreateLogicalBridge(_ context.Context, in *pb.CreateLogicalBrid
myip := make(net.IP, 4)
// TODO: remove hard-coded 167772162 == "10.0.0.2"
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: resourceID}, VxlanId: int(*in.LogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
vxlanName := fmt.Sprintf("vni%d", *in.LogicalBridge.Spec.Vni)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(*in.LogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
log.Printf("Creating Vxlan %v", vxlan)
// TODO: take Port from proto instead of hard-coded
if err := s.nLink.LinkAdd(vxlan); err != nil {
Expand Down Expand Up @@ -125,13 +126,13 @@ func (s *Server) DeleteLogicalBridge(_ context.Context, in *pb.DeleteLogicalBrid
log.Printf("error: %v", err)
return nil, err
}
resourceID := path.Base(obj.Name)
// only if VNI is not empty
if obj.Spec.Vni != nil {
// use netlink to find vxlan device
vxlan, err := s.nLink.LinkByName(resourceID)
vxlanName := fmt.Sprintf("vni%d", *obj.Spec.Vni)
vxlan, err := s.nLink.LinkByName(vxlanName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", resourceID)
err := status.Errorf(codes.NotFound, "unable to find key %s", vxlanName)
log.Printf("error: %v", err)
return nil, err
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/evpn/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,25 @@ func Test_CreateLogicalBridge(t *testing.T) {
// myip := net.ParseIP("10.0.0.2")
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
vxlanName := fmt.Sprintf("vni%d", *testLogicalBridge.Spec.Vni)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(errors.New(tt.errMsg)).Once()
} else if strings.Contains(name, "failed LinkSetMaster") {
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
vxlanName := fmt.Sprintf("vni%d", *testLogicalBridge.Spec.Vni)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(nil).Once()
mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(errors.New(tt.errMsg)).Once()
} else if strings.Contains(name, "failed LinkSetUp") {
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
vxlanName := fmt.Sprintf("vni%d", *testLogicalBridge.Spec.Vni)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(nil).Once()
Expand All @@ -219,7 +222,8 @@ func Test_CreateLogicalBridge(t *testing.T) {
} else if strings.Contains(name, "failed BridgeVlanAdd") {
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
vxlanName := fmt.Sprintf("vni%d", *testLogicalBridge.Spec.Vni)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(nil).Once()
Expand Down

0 comments on commit e21063e

Please sign in to comment.