Skip to content

Commit 62d21ea

Browse files
committed
enforcing single uplink in routing mode
1 parent e756258 commit 62d21ea

File tree

5 files changed

+63
-26
lines changed

5 files changed

+63
-26
lines changed

ofnetAgent.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,14 @@ func (self *OfnetAgent) UpdateUplink(uplinkName string, portUpds PortUpdates) er
872872
// RemoveUplink remove an uplink to the switch
873873
func (self *OfnetAgent) RemoveUplink(uplinkName string) error {
874874
// Call the datapath
875-
return self.datapath.RemoveUplink(uplinkName)
875+
err := self.datapath.RemoveUplink(uplinkName)
876+
if err != nil {
877+
return err
878+
}
879+
if self.protopath != nil {
880+
self.protopath.SetRouterInfo(nil)
881+
}
882+
return nil
876883
}
877884

878885
// AddSvcSpec adds a service spec to proxy
@@ -996,18 +1003,20 @@ func (self *OfnetAgent) AddBgp(routerIP string, As string, neighborAs string, pe
9961003
log.Errorf("Ofnet is not initialized in routing mode")
9971004
return errors.New("Ofnet not in routing mode")
9981005
}
1006+
9991007
routerInfo := &OfnetProtoRouterInfo{
10001008
ProtocolType: "bgp",
10011009
RouterIP: routerIP,
10021010
As: As,
10031011
}
1012+
10041013
neighborInfo := &OfnetProtoNeighborInfo{
10051014
ProtocolType: "bgp",
10061015
NeighborIP: peer,
10071016
As: neighborAs,
10081017
}
10091018
rinfo := self.GetRouterInfo()
1010-
if rinfo != nil {
1019+
if rinfo != nil && len(rinfo.RouterIP) != 0 {
10111020
self.DeleteBgp()
10121021
}
10131022

ofnetBgp.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ Bgp serve routine does the following:
9797
*/
9898
func (self *OfnetBgp) StartProtoServer(routerInfo *OfnetProtoRouterInfo) error {
9999

100+
if self.uplinkPort == nil {
101+
return fmt.Errorf("Unable to start protocol server without uplink")
102+
}
103+
100104
log.Infof("Starting the Bgp Server with %#v", routerInfo)
101105

102106
//Flush previous external endpoints if any
@@ -344,6 +348,7 @@ func (self *OfnetBgp) GetRouterInfo() *OfnetProtoRouterInfo {
344348
if self.routerIP == "" {
345349
return nil
346350
}
351+
347352
routerInfo := &OfnetProtoRouterInfo{
348353
ProtocolType: "bgp",
349354
RouterIP: self.routerIP,
@@ -596,8 +601,12 @@ func (self *OfnetBgp) InspectProto() (interface{}, error) {
596601
}
597602

598603
func (self *OfnetBgp) SetRouterInfo(uplink *PortInfo) error {
599-
log.Infof("Received Set Router info for %v \n", uplink)
600-
if uplink != nil && len(uplink.MbrLinks) == 0 {
604+
log.Infof("Received Set Router info for %+v \n", uplink)
605+
if uplink == nil {
606+
self.uplinkPort = nil
607+
return nil
608+
}
609+
if len(uplink.MbrLinks) == 0 {
601610
return fmt.Errorf("L3 routing mode currently requires atleast one uplink interface. Num uplinks active: 0")
602611
}
603612
uplink.checkLinkStatus()

ofnet_port_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ func TestUplinkPortCreateDelete(t *testing.T) {
4747
if err != nil {
4848
t.Fatalf("Uplink port deletion failed for vlrouter agent: %+v", err)
4949
}
50-
51-
// Check uplink bonded port creation in vlrouter mode
52-
err = addUplink(vlrtrAgents[0], uplinkBondedPort)
53-
if err == nil {
54-
t.Fatalf("Uplink port creation with multiple interfaces expected to fail for vlrouter agent: %+v", err)
55-
}
5650
}
5751

5852
func TestPortActiveLinksStateChange(t *testing.T) {

ofnet_route_test.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,14 @@ func TestOfnetBgpPeerAddDelete(t *testing.T) {
344344
routerIP := "50.1.1.1/24"
345345
as := "65002"
346346
//Add Bgp neighbor and check if it is successful
347-
347+
uplinkSinglePort := createPort("upPort")
348348
for i := 0; i < NUM_VLRTR_AGENT; i++ {
349-
err := vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
349+
err := addUplink(vlrtrAgents[0], uplinkSinglePort)
350+
if err != nil {
351+
t.Fatalf("Uplink port creation failed for vlrouter agent: %+v", err)
352+
}
353+
time.Sleep(2 * time.Second)
354+
err = vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
350355
if err != nil {
351356
t.Errorf("Error adding Bgp Neighbor: %v", err)
352357
return
@@ -383,6 +388,10 @@ func TestOfnetBgpPeerAddDelete(t *testing.T) {
383388
t.Errorf("Neighbor is not deleted: %v", err)
384389
return
385390
}
391+
err = delUplink(vlrtrAgents[0], uplinkSinglePort)
392+
if err != nil {
393+
t.Fatalf("Uplink port deletion failed for vlrouter agent: %+v", err)
394+
}
386395
}
387396
}
388397

@@ -393,11 +402,15 @@ func TestOfnetVlrouteAddDelete(t *testing.T) {
393402
routerIP := "50.1.1.1/24"
394403
as := "65002"
395404
//Add Bgp neighbor and check if it is successful
396-
405+
uplinkSinglePort := createPort("upPort")
397406
for i := 0; i < NUM_VLRTR_AGENT; i++ {
398-
err := vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
407+
err := addUplink(vlrtrAgents[0], uplinkSinglePort)
408+
if err != nil {
409+
t.Fatalf("Uplink port creation failed for vlrouter agent: %+v", err)
410+
}
411+
time.Sleep(2 * time.Second)
412+
err = vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
399413
if err != nil {
400-
log.Infof("THE ERROR IS %s", err)
401414
t.Errorf("Error adding Bgp Neighbor: %v", err)
402415
return
403416
}
@@ -488,7 +501,11 @@ func TestOfnetVlrouteAddDelete(t *testing.T) {
488501
t.Errorf("Still found the flow %s on ovs %s", ipFlowMatch, brName)
489502
}
490503
// verify IPv6 flow entry exists
491-
err = vlrtrAgents[i].DeleteBgp()
504+
vlrtrAgents[i].DeleteBgp()
505+
err = delUplink(vlrtrAgents[0], uplinkSinglePort)
506+
if err != nil {
507+
t.Fatalf("Uplink port deletion failed for vlrouter agent: %+v", err)
508+
}
492509
log.Infof("Verified all flows are deleted")
493510
}
494511
}
@@ -501,9 +518,13 @@ func TestOfnetBgpVlrouteAddDelete(t *testing.T) {
501518
routerIP := "50.1.1.2/24"
502519
as := "65002"
503520
//Add Bgp neighbor and check if it is successful
504-
521+
uplinkSinglePort := createPort("upPort")
505522
for i := 0; i < NUM_VLRTR_AGENT; i++ {
506-
err := vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
523+
err := addUplink(vlrtrAgents[0], uplinkSinglePort)
524+
if err != nil {
525+
t.Fatalf("Uplink port creation failed for vlrouter agent: %+v", err)
526+
}
527+
err = vlrtrAgents[i].AddBgp(routerIP, as, neighborAs, peer)
507528
time.Sleep(5 * time.Second)
508529
if err != nil {
509530
t.Errorf("Error adding Bgp Neighbor: %v", err)
@@ -556,5 +577,9 @@ func TestOfnetBgpVlrouteAddDelete(t *testing.T) {
556577
return
557578
}
558579
log.Infof("ipflow %s on ovs %s has been deleted from OVS", ipFlowMatch, brName)
580+
err = delUplink(vlrtrAgents[0], uplinkSinglePort)
581+
if err != nil {
582+
t.Fatalf("Uplink port deletion failed for vlrouter agent: %+v", err)
583+
}
559584
}
560585
}

vlrouter.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ func (vl *Vlrouter) processArp(pkt protocol.Ethernet, inPort uint32) {
10061006
if vl.agent.GetRouterInfo() != nil {
10071007
uplink := vl.agent.GetRouterInfo().UplinkPort
10081008

1009-
if uplink != nil && len(uplink.MbrLinks) == 0 {
1009+
if uplink == nil || len(uplink.MbrLinks) == 0 {
10101010
log.Errorf("Error getting interface information. Err: No member links present")
10111011
return
10121012
}
@@ -1147,12 +1147,12 @@ func (vl *Vlrouter) resolveUnresolvedEPs(MacAddrStr string, portNo uint32) {
11471147
func (vl *Vlrouter) AddUplink(uplinkPort *PortInfo) error {
11481148
log.Infof("Adding uplink: %+v", uplinkPort)
11491149

1150-
if len(uplinkPort.MbrLinks) != 1 {
1151-
err := fmt.Errorf("Only one uplink interface supported in vlrouter mode. Num uplinks configured: %d", len(uplinkPort.MbrLinks))
1152-
log.Errorf("Error adding uplink: %+v", err)
1150+
if len(uplinkPort.MbrLinks) == 0 {
1151+
err := fmt.Errorf("Atleast one uplink is needed to be configured for routing mode. Num uplinks configured: %d", len(uplinkPort.MbrLinks))
11531152
return err
11541153
}
11551154

1155+
uplinkPort.MbrLinks = uplinkPort.MbrLinks[:1]
11561156
linkInfo := uplinkPort.MbrLinks[0]
11571157
vl.uplinkOfp = linkInfo.OfPort
11581158
dnsUplinkFlow, err := vl.inputTable.NewFlow(ofctrl.FlowMatch{
@@ -1297,12 +1297,12 @@ func (vl *Vlrouter) sendArpPacketOut(srcIP, dstIP net.IP) {
12971297
for uplinkObj := range vl.uplinkPortDb.IterBuffered() {
12981298
uplink := uplinkObj.Val.(*PortInfo)
12991299
uplinkMemberLink = uplink.getActiveLink()
1300-
if uplinkMemberLink == nil {
1301-
log.Debugf("No active interface on uplink. Not sending ARP for IP:%s \n", dstIP.String())
1302-
return
1303-
}
13041300
break
13051301
}
1302+
if uplinkMemberLink == nil {
1303+
log.Debugf("No active interface on uplink. Not sending ARP for IP:%s \n", dstIP.String())
1304+
return
1305+
}
13061306

13071307
ofPortno := uplinkMemberLink.OfPort
13081308
intf, _ := net.InterfaceByName(uplinkMemberLink.Name)

0 commit comments

Comments
 (0)