Skip to content

Commit

Permalink
Merge pull request #272 from jojimt/I271-aci
Browse files Browse the repository at this point in the history
Fix #271
  • Loading branch information
jojimt committed Feb 6, 2016
2 parents 392e0a7 + 88ba4dc commit 8b02e0f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 16 deletions.
4 changes: 2 additions & 2 deletions drivers/ovsSwitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func getOvsPostName(intfName string) string {
}

// CreatePort creates a port in ovs switch
func (sw *OvsSwitch) CreatePort(intfName string, cfgEp *mastercfg.CfgEndpointState, pktTag int) error {
func (sw *OvsSwitch) CreatePort(intfName string, cfgEp *mastercfg.CfgEndpointState, pktTag, nwPktTag int) error {
var ovsIntfType string

// Get OVS port name
Expand Down Expand Up @@ -303,7 +303,7 @@ func (sw *OvsSwitch) CreatePort(intfName string, cfgEp *mastercfg.CfgEndpointSta
endpoint := ofnet.EndpointInfo{
PortNo: ofpPort,
MacAddr: macAddr,
Vlan: uint16(pktTag),
Vlan: uint16(nwPktTag),
IpAddr: net.ParseIP(cfgEp.IPAddress),
EndpointGroup: cfgEp.EndpointGroupID,
}
Expand Down
24 changes: 11 additions & 13 deletions drivers/ovsdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,22 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
return err
}

// Get the nw config.
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err = cfgNw.Read(cfgEp.NetID)
if err != nil {
log.Errorf("Unable to get network %s. Err: %v", cfgEp.NetID, err)
return err
}

cfgEpGroup := &mastercfg.EndpointGroupState{}
cfgEpGroup.StateDriver = d.oper.StateDriver
err = cfgEpGroup.Read(strconv.Itoa(cfgEp.EndpointGroupID))
if err == nil {
log.Debugf("pktTag: %v ", cfgEpGroup.PktTag)
} else if core.ErrIfKeyExists(err) == nil {
// FIXME: this should be deprecated once we remove old style intent
// In case EpGroup is not specified, get the tag from nw.
// this is mainly for the intent based system tests
log.Warnf("%v will use network based tag ", err)
cfgNw := mastercfg.CfgNetworkState{}
cfgNw.StateDriver = d.oper.StateDriver
err1 := cfgNw.Read(cfgEp.NetID)
if err1 != nil {
log.Errorf("Unable to get tag neither epg nor nw")
return err1
}

log.Infof("%v will use network based tag ", err)
cfgEpGroup.PktTagType = cfgNw.PktTagType
cfgEpGroup.PktTag = cfgNw.PktTag
} else {
Expand Down Expand Up @@ -289,7 +287,7 @@ func (d *OvsDriver) CreateEndpoint(id string) error {
}

// Ask the switch to create the port
err = sw.CreatePort(intfName, cfgEp, cfgEpGroup.PktTag)
err = sw.CreatePort(intfName, cfgEp, cfgEpGroup.PktTag, cfgNw.PktTag)
if err != nil {
log.Errorf("Error creating port %s. Err: %v", intfName, err)
return err
Expand Down
9 changes: 8 additions & 1 deletion drivers/ovsdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func createCommonState(stateDriver core.StateDriver) error {
cfgEp := &mastercfg.CfgEndpointState{}
cfgEp.ID = createEpIDStateful
cfgEp.EndpointGroupID = testOvsEpgHandleStateful
cfgEp.NetID = testOvsNwID
cfgEp.NetID = testOvsNwIDStateful
cfgEp.IntfName = ""
cfgEp.IPAddress = testEpAddress
cfgEp.MacAddress = testEpMacAddress
Expand Down Expand Up @@ -375,6 +375,13 @@ func TestOvsDriverCreateEndpointStatefulStateMismatch(t *testing.T) {
}
defer func() { driver.DeleteNetwork(testOvsNwID, "", testPktTag, testExtPktTag, testGateway) }()

// create second network
err = driver.CreateNetwork(testOvsNwIDStateful)
if err != nil {
t.Fatalf("network creation failed. Error: %s", err)
}
defer func() { driver.DeleteNetwork(testOvsNwIDStateful, "", testPktTagStateful, testExtPktTag, testGateway) }()

// create endpoint
err = driver.CreateEndpoint(id)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions scripts/python/api/objmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,3 +475,20 @@ def deleteTenant(tenantName):
def listTenant():
# Get the list of Tenants
return json.loads(urllib2.urlopen('http://localhost:9999/api/tenants/').read())

# Configure ACI Mode
def setFabricMode(mode):
postUrl = 'http://netmaster:9999/api/globals/global/'
jdata = json.dumps({
"name": "global",
"network-infra-type": mode,
"vlans": "1-4094",
"vxlans": "1-10000",
})
response = httpPost(postUrl, jdata)

# Check for error
if response == "Error":
print response
errorExit("setFabricMode failed")

7 changes: 7 additions & 0 deletions scripts/python/api/tbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ def runContainersInGroups(self, numContainer, groups):

return containers

# Start a container on the specified node
def runContainerOnNode(self, nodeIdx, group):
netName = group.split(".")[1]
svcName = group.split('.')[0]
cnt = self.nodes[nodeIdx].runContainer("ubuntu", networkName=netName, serviceName=svcName)
return cnt

# Remove containers
def removeContainers(self, containers):
# remove containers
Expand Down
4 changes: 4 additions & 0 deletions scripts/python/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import testcases.tcPolicy
import testcases.tcNetwork
import testcases.tcTrigger
import testcases.tcAci
import argparse
import os
import exceptions
Expand Down Expand Up @@ -83,6 +84,9 @@
# Run multiple triggers on the Testbed
testcases.tcTrigger.testMultiTrigger(testbed, (numIteration * numTriggerTests))

# Run ACI mode sanity
testcases.tcAci.testACIMode(testbed)

# Cleanup testbed
testbed.cleanup()

Expand Down
48 changes: 48 additions & 0 deletions scripts/python/testcases/tcAci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import api.tutils
import time
import sys
import api.objmodel

# Test configure ACI mode
def testACIMode(testbed):
api.tutils.info("testACIMode starting")
api.objmodel.setFabricMode("aci")

# Create a network
testTen = api.objmodel.tenant('default')
testNet = testTen.newNetwork("aciNet", 0, "22.2.2.0/24", "22.2.2.254", "vlan")

# Create two epgs
epgA = testNet.newGroup("epgA")
epgB = testNet.newGroup("epgB")

# Start two containers each on epgA and epgB
cA1 = testbed.runContainerOnNode(0, "epgA.aciNet")
cA2 = testbed.runContainerOnNode(0, "epgA.aciNet")
cB1 = testbed.runContainerOnNode(0, "epgB.aciNet")
cB2 = testbed.runContainerOnNode(0, "epgB.aciNet")

# Verify cA1 can ping cA2
cA1.checkPing(cA2.getIpAddr())

# Verify cB1 can ping cB2
cB1.checkPing(cB2.getIpAddr())

# Verify cA1 cannot ping cB1
cA1.checkPingFailure(cB1.getIpAddr())

# remove containers
testbed.removeContainers([cA1, cA2, cB1, cB2])

# delete epgs
testNet.deleteGroup("epgA")
testNet.deleteGroup("epgB")

# delete network
testTen.deleteNetwork("aciNet")
api.objmodel.setFabricMode("default")

# Check for errors
testbed.chekForNetpluginErrors()

api.tutils.info("testACIMode Test passed")

0 comments on commit 8b02e0f

Please sign in to comment.