Exemplo n.º 1
0
def step_routeIdentification(context, hst1, hst2, sw):
    s1 = MininetHelper.getNodeFromName(context.mini, sw)
    h1 = MininetHelper.getNodeFromName(context.mini, hst1)
    h2 = MininetHelper.getNodeFromName(context.mini, hst2)
    #buil FlowTable
    s1FlowTable = MininetHelper.createFlowTable(s1)
    hasEntry = s1FlowTable.hasForwardingEntry(h1.MAC(), h2.MAC())
    assert_that(hasEntry, equal_to(True),
                "switch %s has dl_dst entry for traffic" % sw)
Exemplo n.º 2
0
def step_httpRequest(context, hst1, hst2):
    h1 = MininetHelper.getNodeFromName(context.mini, hst1)
    h2 = MininetHelper.getNodeFromName(context.mini, hst2)
    #send request
    cmdString = "wget -O - --tries=2  -T30 %s" % h2.IP()
    responseArray = h1.pexec(cmdString)
    #write response (Exitcode) in context variable
    response = responseArray[2]
    context.httpRequestExitcode = response
Exemplo n.º 3
0
def step_build_topo_1(context):
    # OpenStack part
    if (context.openStackTest == True):
        workingDir = "terraformFiles/tree_3sw_4h"
        context.tf = TerraformHelper(workingDir, context.behaveLogLevel)
        context.tf.build_topo_4()
        #provide controllers IP
        context.controllerIp = context.tf.tf_get("controller_fip")
        #provide ONOS-Rest access
        context.onosRest = OnosRestAPI(context.controllerIp)
    else:
        # Mininet part
        mnHelper = MininetHelper()
        mnHelper.build_topo_4(context.mini)
Exemplo n.º 4
0
def step_linkDown(context, nd1, nd2):
    node1 = MininetHelper.getNodeFromName(context.mini, nd1)
    node2 = MininetHelper.getNodeFromName(context.mini, nd2)
    #check if link between nodes is existing
    connectionList = node1.connectionsTo(node2)
    assert_that(len(connectionList), greater_than(0),
                "Link between %s and %s found" % (nd1, nd2))
    #find the correct link and stop it => link status will be set to "MISSING"
    for link in context.mini.links:
        if ((str(node1.name + "-") in str(link.intf1)
             and str(node2.name + "-") in str(link.intf2))
                or (str(node1.name + "-") in str(link.intf2)
                    and str(node2.name + "-") in str(link.intf1))):
            link.stop()
Exemplo n.º 5
0
def step_build_topo_1(context):
    # OpenStack part
    if (context.openStackTest == True):
        #deploy infrastructure and configure ports
        workingDir = "terraformFiles/flat_1sw_2h"
        context.tf = TerraformHelper(workingDir, context.behaveLogLevel)
        context.tf.build_topo_1()
        #provide controllers IP
        context.controllerIp = context.tf.tf_get("controller_fip")
        #provide ONOS-Rest access
        context.onosRest = OnosRestAPI(context.controllerIp)
    else:
        # Mininet part
        mnHelper = MininetHelper()
        mnHelper.build_topo_1(context.mini)
Exemplo n.º 6
0
def step_ping(context, hst1, hst2):
    # OpenStack part
    if (context.openStackTest == True):
        '''
        validate nodes
        send ping
        return packetLoss (pingResult)
        '''
        context.tf.validateNodes((hst1, hst2))
        # set host to host intents (get names of hst1/hst2, add "_mac" to get terraform output)
        #ping once for ONOS host detection
        pingOnce = True
        context.tf.ping(hst1, hst2, pingOnce)
        hst1_mac = context.tf.tf_get(
            context.tf.translateHostName(hst1) + "_mac")
        hst2_mac = context.tf.tf_get(
            context.tf.translateHostName(hst2) + "_mac")
        context.onosRest.setOnosIntent(hst1_mac, hst2_mac)
        packetLoss = context.tf.ping(hst1, hst2, False)
    else:
        # Mininet part
        h1 = MininetHelper.getNodeFromName(context.mini, hst1)
        h2 = MininetHelper.getNodeFromName(context.mini, hst2)
        # if controller = ONOS set host intents
        if (context.onosFlag):
            context.onosRest.setOnosIntent(h1.MAC(h1.name + "-eth0"),
                                           h2.MAC(h2.name + "-eth0"))
        timeout = "5"
        packetLoss = 100
        pingCounter = 0
        pingMaxCount = 5
        while packetLoss > 0 and pingCounter < pingMaxCount:
            if (pingCounter > 0):
                #wait some time between two pings
                sleep(1)
            packetLoss = context.mini.ping((h1, h2), timeout)
            pingCounter += 1
    context.pingResult = packetLoss
Exemplo n.º 7
0
def step_test_connection(context, sw1, sw2):
    s1 = MininetHelper.getNodeFromName(context.mini, sw1)
    s2 = MininetHelper.getNodeFromName(context.mini, sw2)
    connectionList = s1.connectionsTo(s2)
    # at least one link is existing -> check all links
    if (len(context.mini.links) > 0):
        for link in context.mini.links:
            #check if link between nodes is existing, if so check status
            if (str(sw1 + "-") in link.__str__()
                    and str(sw2 + "-") in link.__str__()):
                #link is existing and status must be (MISSING MISSING)
                #print(link)
                assert_that(
                    link.status(), equal_to("(MISSING MISSING)"),
                    "Link %s <-> %s found with status %s" %
                    (sw1, sw2, link.status()))
            else:
                #link between nodes is not existing
                assert_that(
                    str(sw1 + "-") in link.__str__()
                    and str(sw2 + "-") in link.__str__(), equal_to(False))
    else:
        #no links at all
        assert_that(len(connectionList), equal_to(0))
Exemplo n.º 8
0
def step_startWebserver(context, hst):
    serverNode = MininetHelper.getNodeFromName(context.mini, hst)
    #start Webserver
    cmdString = "python -m SimpleHTTPServer 80 &"
    serverNode.cmd(cmdString)
Exemplo n.º 9
0
def step_connectHosts(context, hst, sw):
    if MininetHelper.validateNodes(context.mini, (hst, sw)):
        context.mini.addLink(hst, sw)
Exemplo n.º 10
0
def step_connect(context, sw1, sw2):
    #validation (switches existing?)
    if MininetHelper.validateNodes(context.mini, (sw1, sw2)):
        context.mini.addLink(sw1, sw2)
Exemplo n.º 11
0
def step_fullMeshedNet(context):
    MininetHelper.createFullMeshedNet(context.mini)
Exemplo n.º 12
0
def step_addHost(context, number):
    numberOfHosts = NumberConverter.convertNumber(number)
    MininetHelper.addHosts(context.mini, numberOfHosts)
Exemplo n.º 13
0
def step_addSwitches(context, number):
    numberOfSwitches = NumberConverter.convertNumber(number)
    MininetHelper.addSwitches(context.mini, numberOfSwitches)
Exemplo n.º 14
0
def step_test_connection(context, sw1, sw2):
    s1 = MininetHelper.getNodeFromName(context.mini, sw1)
    s2 = MininetHelper.getNodeFromName(context.mini, sw2)
    connectionList = s1.connectionsTo(s2)
    assert_that(len(connectionList), greater_than(0),
                "Link %s <-> %s found" % (sw1, sw2))