Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge): create vxlan only if VNI is not empty #98

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions pkg/evpn/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,40 +59,43 @@
log.Print(msg)
return nil, status.Errorf(codes.InvalidArgument, msg)
}
bridgeName := "br-tenant"
bridge, err := netlink.LinkByName(bridgeName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", bridgeName)
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
vxlanName := fmt.Sprintf("vxlan%d", in.LogicalBridge.Spec.VlanId)
myip := make(net.IP, 4)
// TODO: remove hard-coded 167772260 == "10.0.0.100"
binary.BigEndian.PutUint32(myip, 167772260)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(in.LogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
// TODO: take Port from proto instead of hard-coded
if err := netlink.LinkAdd(vxlan); err != nil {
fmt.Printf("Failed to create Vxlan link: %v", err)
return nil, err
}
// Example: ip link set vxlan-<LB-vlan-id> master br-tenant addrgenmode none
if err := netlink.LinkSetMaster(vxlan, bridge); err != nil {
fmt.Printf("Failed to add Vxlan to bridge: %v", err)
return nil, err
}
// Example: ip link set vxlan-<LB-vlan-id> up
if err := netlink.LinkSetUp(vxlan); err != nil {
fmt.Printf("Failed to up Vxlan link: %v", err)
return nil, err
}
// Example: bridge vlan add dev vxlan-<LB-vlan-id> vid <LB-vlan-id> pvid untagged
if err := netlink.BridgeVlanAdd(vxlan, uint16(in.LogicalBridge.Spec.VlanId), true, true, false, false); err != nil {
fmt.Printf("Failed to add vlan to bridge: %v", err)
return nil, err
// create vxlan only if VNI is not empty
if in.LogicalBridge.Spec.Vni > 0 {
bridgeName := "br-tenant"
bridge, err := netlink.LinkByName(bridgeName)
if err != nil {
err := status.Errorf(codes.NotFound, "unable to find key %s", bridgeName)
log.Printf("error: %v", err)
return nil, err
}

Check warning on line 70 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L64-L70

Added lines #L64 - L70 were not covered by tests
// Example: ip link add vxlan-<LB-vlan-id> type vxlan id <LB-vni> local <vtep-ip> dstport 4789 nolearning proxy
vxlanName := fmt.Sprintf("vxlan%d", in.LogicalBridge.Spec.VlanId)
myip := make(net.IP, 4)
// TODO: remove hard-coded 167772260 == "10.0.0.100"
binary.BigEndian.PutUint32(myip, 167772260)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: vxlanName}, VxlanId: int(in.LogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
// TODO: take Port from proto instead of hard-coded
if err := netlink.LinkAdd(vxlan); err != nil {
fmt.Printf("Failed to create Vxlan link: %v", err)
return nil, err
}

Check warning on line 81 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L72-L81

Added lines #L72 - L81 were not covered by tests
// Example: ip link set vxlan-<LB-vlan-id> master br-tenant addrgenmode none
if err := netlink.LinkSetMaster(vxlan, bridge); err != nil {
fmt.Printf("Failed to add Vxlan to bridge: %v", err)
return nil, err
}

Check warning on line 86 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L83-L86

Added lines #L83 - L86 were not covered by tests
// Example: ip link set vxlan-<LB-vlan-id> up
if err := netlink.LinkSetUp(vxlan); err != nil {
fmt.Printf("Failed to up Vxlan link: %v", err)
return nil, err
}

Check warning on line 91 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L88-L91

Added lines #L88 - L91 were not covered by tests
// Example: bridge vlan add dev vxlan-<LB-vlan-id> vid <LB-vlan-id> pvid untagged
if err := netlink.BridgeVlanAdd(vxlan, uint16(in.LogicalBridge.Spec.VlanId), true, true, false, false); err != nil {
fmt.Printf("Failed to add vlan to bridge: %v", err)
return nil, err
}

Check warning on line 96 in pkg/evpn/bridge.go

View check run for this annotation

Codecov / codecov/patch

pkg/evpn/bridge.go#L93-L96

Added lines #L93 - L96 were not covered by tests
// TODO: bridge link set dev vxlan-<LB-vlan-id> neigh_suppress on
}
// TODO: bridge link set dev vxlan-<LB-vlan-id> neigh_suppress on
response := proto.Clone(in.LogicalBridge).(*pb.LogicalBridge)
response.Status = &pb.LogicalBridgeStatus{OperStatus: pb.LBOperStatus_LB_OPER_STATUS_UP}
s.Bridges[in.LogicalBridge.Name] = response
Expand Down
19 changes: 19 additions & 0 deletions pkg/evpn/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ func Test_CreateLogicalBridge(t *testing.T) {
fmt.Sprintf("VlanId value (%v) have to be between 1 and 4095", 4096),
false,
},
"empty vni": {
testLogicalBridgeID,
&pb.LogicalBridge{
Spec: &pb.LogicalBridgeSpec{
VlanId: 11,
},
},
&pb.LogicalBridge{
Spec: &pb.LogicalBridgeSpec{
VlanId: 11,
},
Status: &pb.LogicalBridgeStatus{
OperStatus: pb.LBOperStatus_LB_OPER_STATUS_UP,
},
},
codes.OK,
"",
false,
},
"already exists": {
testLogicalBridgeID,
&testLogicalBridge,
Expand Down
Loading