Exemple #1
0
    def testNextVNFs(self):
        """Tests the next VNFs retrieval method
        :returns: Nothing

        """
        print '##############'
        print '## nextVNFs ##'
        print '##############'

        mockChain = self.__createMockChain()
        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setNfpds(self.__mockNfpds())

        if None == ns.getNextVNF('Renderer', 'aWay'):
            print '  first aWay retrieval: OK!'
        else:
            print '  first aWay retrieval: ERR!'

        if 'WebServer' == ns.getNextVNF('MECa', 'aWay'):
            print '  second aWay retrieval: OK!'
        else:
            print '  second aWay retrieval: ERR!'

        if None == ns.getNextVNF('Renderer', 'bWay'):
            print '  first bWay retrieval: OK!'
        else:
            print '  first bWay retrieval: ERR!'

        if 'WebServer' == ns.getNextVNF('MECb', 'bWay'):
            print '  second bWay retrieval: OK!'
        else:
            print '  second bWay retrieval: ERR!'

        return
Exemple #2
0
    def testGetters(self):
        """Tests the get methods for VNFs and VLs
        :returns: Nothing

        """
        print '#############'
        print '## getters ##'
        print '#############'

        mockChain = self.__createMockChain()
        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setNfpds(self.__mockNfpds())

        wsVNF = ns.getVnf("WebServer")
        if wsVNF['cpu'] == 4 and wsVNF['disk'] == 3 and wsVNF['memory'] == 2:
            print "  WebServer VNF retrieved OK with its properties"
        else:
            print "  WebServer VNF properties are not retrieved properly"

        ws2RenderLinks = ns.getLinks("WebServer", "Renderer")
        if ws2RenderLinks[0]['bw'] == 2 and ws2RenderLinks[0]['delay'] == 3\
                and ws2RenderLinks[1]['bw'] == 20 and\
                ws2RenderLinks[1]['delay'] == 3:
            print "  multiple links between WebServer and Renderer: OK!"
        else:
            print "  the links between WebServer and Renderere BAD"

        return
    def testRandomWalk(self):
        """Tests the random walk to find paths for VNF allocation
        :returns: Nothing

        """
        md = self.__genMultiDomain()
        mapper = NSM.NsMapper(md)
        err = False

        print '#################'
        print '## Random walk ##'
        print '#################'

        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=10, cpu=0)
        chain.add_edge('start', 1, bw=250, delay=90)
        ns.setChain(chain)
        ns.setBranchHeads([1])

        path, delay = mapper.randomWalk(0, 1, {4: None, 5: None}, 90, 250)
        if path == None or (path == [(1, 3), (3, 6), (6, 5)] and delay == 20):
            print '  first mapping worked!'
        else:
            print '  first mapping did not work as expected'

        path, delay = mapper.randomWalk(0, 1, {4: None, 5: None}, 90, 200)
        if path == None or\
                (path == [(1, 3), (3, 6), (6, 5)] and delay == 20) or\
                (path == [(1, 2), (2, 4)] and delay == 22) or\
                (path == [(1, 3), (3, 4)] and delay == 20):
            print '  second mapping worked!'
        else:
            print '  second mapping did not work as expected'
Exemple #4
0
    def testPrevVNFs(self):
        """Tests the previous VNFs retrieval method
        :returns: Nothing

        """
        print '##############'
        print '## prevVNFs ##'
        print '##############'

        mockChain = self.__createMockChain()
        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setNfpds(self.__mockNfpds())

        if None == ns.prevVNF('MECa', 'aWay'):
            print '  first aWay retrieval: OK!'
        else:
            print '  first aWay retrieval: ERR!'

        if "WebServer" == ns.prevVNF("DB", "aWay"):
            print '  second aWay retrieval: OK!'
        else:
            print '  second aWay retrieval: ERR!'

        if None == ns.prevVNF('MECa', 'bWay'):
            print '  first bWay retrieval: OK!'
        else:
            print '  first bWay retrieval: ERR!'

        if "WebServer" == ns.prevVNF("DB", "bWay"):
            print '  second bWay retrieval: OK!'
        else:
            print '  second bWay retrieval: ERR!'

        return
    def __genTabuNS(self):
        """Generates the NS chain used to test the tabu search
        :returns: NS instance

        """
        chain = nx.Graph()
        chain.add_node('start', memory=2, disk=3, cpu=4)
        chain.add_node(1, memory=0, disk=0, cpu=4)
        chain.add_node(2, memory=10, disk=0, cpu=0)
        chain.add_node(3, memory=0, disk=100, cpu=0)
        chain.add_node(4, memory=1, disk=0, cpu=1)
        chain.add_node(5, memory=0, disk=1, cpu=1)
        chain.add_node(6, memory=1, disk=1, cpu=0)

        chain.add_edge('start', 1, bw=0, delay=0)
        chain.add_edge(1, 2, bw=0, delay=3)
        chain.add_edge(1, 3, bw=0, delay=3)
        chain.add_edge(2, 4, bw=0, delay=70)
        chain.add_edge(3, 4, bw=0, delay=70)
        chain.add_edge(4, 5, bw=0, delay=200)
        chain.add_edge(4, 6, bw=0, delay=200)

        ns = NS.NS()
        ns.setChain(chain)
        ns.setSplitsNum(2)
        ns.setBranchNum(2)
        ns.setMaxSplitW(2)
        ns.setBranchHeads([5, 6])

        return ns
    def testIteration(self):
        """Tests the iteration methods over a fixed mock NS chain that could
            have been generated by the NsGenerator
        :returns: Nothing
        """

        mockChain = self.__createMockChain()

        ns = NS.NS()
        ns.setChain(mockChain)
        ns.initIter()

        # Check nodes retrieval
        print '######################'
        print '## Iteration tester ##'
        print '######################'
        correct = True
        nextVnfs = ns.iterNext()

        if [1] != nextVnfs:
            print '  retrieval 1 is not == [1]'
            correct = False

        nextVnfs = ns.iterNext()
        if 2 not in nextVnfs or 4 not in nextVnfs or len(nextVnfs) != 2:
            print '  retrieval 1 is not == [2, 4]'
            correct = False

        nextVnfs = ns.iterNext()
        if [3] != nextVnfs:
            print '  retrieval 3 is not == [3]'
            correct = False

        nextVnfs = ns.iterNext()
        if 5 not in nextVnfs or 6 not in nextVnfs or len(nextVnfs) != 2:
            print '  retrieval 4 is not == [5, 6]'
            correct = False

        nextVnfs = ns.iterNext()
        if [] != nextVnfs:
            print '  retrieval 8 is not == []'
            correct = False

        if correct:
            print '  iteration over the NS works properly!'
    def testBFS(self):
        """Tests the BFS algorithm to find paths between certain nodes-
        :returns: Nothing

        """
        md = self.__genMultiDomain()
        mapper = NSM.NsMapper(md)
        err = False

        print '#########'
        print '## BFS ##'
        print '#########'

        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=10, cpu=0)
        chain.add_edge('start', 1, bw=250, delay=90)
        ns.setChain(chain)
        ns.setBranchHeads([1])

        path, delay = mapper.BFS(0, 1, {4: None, 5: None}, 20, 250)
        if path == [(1, 3), (3, 6), (6, 5)] and delay == 20:
            print '  first mapping worked!'
        else:
            print '  first mapping did not work as expected'

        path, _ = mapper.BFS(0, 1, {4: None, 5: None}, 20, 250, depth=2)
        if path == None:
            print '  second mapping worked!'
        else:
            print '  second mapping did not work as expected'

        path, delay = mapper.BFS(0, 1, {4: None, 5: None}, 90, 200)
        if path == [(1, 2), (2, 4)] and delay == 22:
            print '  third mapping worked!'
        else:
            print '  third mapping did not work as expected'

        path, _ = mapper.BFS(0, 1, {4: None, 5: None}, 90, 200, depth=1)
        if path == None:
            print '  fourth mapping worked!'
        else:
            print '  fourth mapping did not work as expected'
    def testNextVNFs(self):
        """Tests the next VNFs retrieval method
        :returns: Nothing

        """
        print '##############'
        print '## nextVNFs ##'
        print '##############'

        mockChain = self.__createMockChain()
        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setSplitsNum(2)
        ns.setBranchNum(3)
        ns.setMaxSplitW(2)

        nexts = ns.getNextVNFs('start')
        if nexts == [1]:
            print '  first retrieval: OK!'
        else:
            print '  first retrieval: ERR!'

        nexts = ns.getNextVNFs(1)
        if 2 in nexts and 4 in nexts:
            print '  second retrieval: OK!'
        else:
            print '  second retrieval: ERR!'

        nexts = ns.getNextVNFs(5)
        if nexts == []:
            print '  third retrieval: OK!'
        else:
            print '  third retrieval: ERR!'

        if 2 in ns._NS__nextNeighsCache[1] and\
                4 in ns._NS__nextNeighsCache[1] and\
                [1] == ns._NS__nextNeighsCache['start'] and\
                [] == ns._NS__nextNeighsCache[5]:
            print '  cache storage: OK!'
        else:
            print '  cache storage: ERR!'
    def testPrevVNFs(self):
        """Tests the previous VNFs retrieval method
        :returns: Nothing

        """
        print '##############'
        print '## prevVNFs ##'
        print '##############'

        mockChain = self.__createMockChain()
        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setSplitsNum(2)
        ns.setBranchNum(3)
        ns.setMaxSplitW(2)

        prevs = ns.prevVNFs('start')
        if prevs == []:
            print '  first retrieval: OK!'
        else:
            print '  first retrieval: ERR!'

        prevs = ns.prevVNFs(1)
        if prevs == ['start']:
            print '  second retrieval: OK!'
        else:
            print '  second retrieval: ERR!'

        prevs = ns.prevVNFs(2)
        if prevs == [1]:
            print '  third retrieval: OK'
        else:
            print '  third retrieval: ERR'

        if ns._NS__prevNeighsCache[1] == ['start'] and\
                ns._NS__prevNeighsCache[2] == [1]:
            print '  cache storage works: OK!'
        else:
            print '  cache storage works: ERR!'
    def genNS(self):
        """Generates the NS that will be used for testing methods.
        :returns: NS instance

        """
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=2, disk=3, cpu=4)
        chain.add_node(2, memory=2, disk=3, cpu=4)
        chain.add_node(3, memory=2, disk=3, cpu=4)
        chain.add_node(4, memory=2, disk=3, cpu=4)
        chain.add_node(5, memory=2, disk=3, cpu=4)
        chain.add_node(6, memory=2, disk=3, cpu=4)
        chain.add_node(7, memory=2, disk=3, cpu=4)
        chain.add_node(8, memory=2, disk=3, cpu=4)
        chain.add_node(9, memory=2, disk=3, cpu=4)

        chain.add_edge('start', 1, bw=2, delay=100)
        chain.add_edge(1, 2, bw=2, delay=100)
        chain.add_edge(1, 3, bw=2, delay=100)
        chain.add_edge(2, 4, bw=2, delay=100)
        chain.add_edge(3, 4, bw=2, delay=100)
        chain.add_edge(4, 5, bw=2, delay=100)
        chain.add_edge(4, 6, bw=2, delay=100)
        chain.add_edge(5, 7, bw=2, delay=100)
        chain.add_edge(6, 7, bw=2, delay=100)
        chain.add_edge(7, 8, bw=2, delay=100)
        chain.add_edge(7, 9, bw=2, delay=100)

        ns = NS.NS()
        ns.setChain(chain)
        ns.setSplitsNum(3)
        ns.setBranchNum(2)
        ns.setMaxSplitW(2)
        ns.setBranchHeads([8, 9])

        return ns
Exemple #11
0
    def testReadWrite(self):
        """Tests the reading and writing methods
        :returns: Nothing

        """

        print '###################'
        print '## testReadWrite ##'
        print '###################'

        mockChain = self.__createMockChain()
        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setSplitsNum(2)
        ns.setBranchNum(3)
        ns.setMaxSplitW(2)

        ns.write('test')
        nsRead = NS.NS.read('test')

        if nsRead.compare(ns):
            print '  read and write is performed correctly!'
        else:
            print '  read and written NSs are not the same'
Exemple #12
0
    def testWatch(self):
        """Tests the watch method, unwatch method, changeConnection method
        :returns: Nothing

        """
        print '###########'
        print '## watch ##'
        print '###########'

        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=1, disk=1, cpu=1)
        chain.add_node(2, memory=1, disk=1, cpu=1)
        chain.add_edge('start', 1, bw=50, delay=90)
        chain.add_edge(1, 2, bw=100, delay=90)
        ns.setChain(chain)

        md = self.__genMultiDomain()
        watchDog = RW.ResourcesWatchDog(md, ns, 0)

        # Map the first VNF
        watchDog.watch('start', 1, [(1, 3), (3, 4)])
        lnkRes13 = md.getLnkRes(0, 1, 3)
        lnkRes34 = md.getLnkRes(0, 3, 4)
        servRes = md.getServerRes(0, 4)

        if lnkRes13['bw'] != 250 or lnkRes34['bw'] != 150 or\
                servRes['memory'] != 1 or servRes['disk'] != 49 or\
                servRes['cpu'] != 3:
            print '  first watch: ERR'
        else:
            print '  first watch: OK'

        # Map the second VNF
        watchDog.watch(1, 2, [(5, 5)])
        servRes5 = md.getServerRes(0, 5)

        if servRes5['memory'] != 1 or servRes5['disk'] != 49 or\
                servRes5['cpu'] != 3:
            print '  second watch: ERR'
        else:
            print '  second watch: OK'

        print '######################'
        print '## changeConnection ##'
        print '######################'

        watchDog.changeConnection('start', 1, [(1, 6), (6, 5)])
        lnkRes13 = md.getLnkRes(0, 1, 3)
        lnkRes34 = md.getLnkRes(0, 3, 4)
        lnkRes16 = md.getLnkRes(0, 1, 6)
        lnkRes65 = md.getLnkRes(0, 6, 5)
        servRes4 = md.getServerRes(0, 4)
        servRes5 = md.getServerRes(0, 5)

        if lnkRes13['bw'] != 300 or lnkRes34['bw'] != 200 or\
                lnkRes16['bw'] != 50 or lnkRes65['bw'] != 200 or\
                servRes4['memory'] != 2 or servRes4['disk'] != 50 or\
                servRes4['cpu'] != 4 or servRes5['memory'] != 0 or\
                servRes5['disk'] != 48 or servRes5['cpu'] != 2:
            print '  first change of connection: ERR!'
        else:
            print '  first change of connection: OK!'

        print '#############'
        print '## unwatch ##'
        print '#############'

        watchDog.unWatch()
        lnkRes13 = md.getLnkRes(0, 1, 3)
        lnkRes34 = md.getLnkRes(0, 3, 4)
        lnkRes16 = md.getLnkRes(0, 1, 6)
        lnkRes65 = md.getLnkRes(0, 6, 5)
        servRes4 = md.getServerRes(0, 4)
        servRes5 = md.getServerRes(0, 5)

        if lnkRes13['bw'] != 300 or lnkRes34['bw'] != 200 or\
                lnkRes16['bw'] != 100 or lnkRes65['bw'] != 250 or\
                servRes4['memory'] != 2 or servRes4['disk'] != 50 or\
                servRes4['cpu'] != 4 or servRes5['memory'] != 2 or\
                servRes5['disk'] != 50 or servRes5['cpu'] != 4:
            print '  resource liberation: ERR!'
        else:
            print '  resource liberation: OK!'
Exemple #13
0
    def testIteration(self):
        """Tests the iteration methods over a fixed mock NS chain that could
            have been generated by the NsGenerator
        :returns: Nothing
        """

        mockChain = self.__createMockChain()

        ns = NS.NS()
        ns.setChain(mockChain)
        ns.setNfpds(self.__mockNfpds())
        ns.initIter()

        # Check nodes retrieval
        print '######################'
        print '## Iteration tester ##'
        print '######################'
        correct = True

        # aWay iteration #
        nextVnf = ns.iterNext("aWay")
        print "# starting with Nfpd=aWay"
        if "MECa" != nextVnf:
            print '  aWay retrieval 1 is not == MECa'
            correct = False

        if "WebServer" != ns.iterNext("aWay"):
            print '  aWay retrieval 2 is not == WebServer'
            correct = False

        if "DB" != ns.iterNext("aWay"):
            print '  aWay retrieval 3 is not == DB'
            correct = False

        if "WebServer" != ns.iterNext("aWay"):
            print '  aWay retrieval 4 is not == WebServer'
            correct = False

        if "DB" != ns.iterNext("aWay"):
            print '  aWay retrieval 5 is not == DB'
            correct = False

        if "WebServer" != ns.iterNext("aWay"):
            print '  aWay retrieval 6 is not == WebServer'
            correct = False

        if "Renderer" != ns.iterNext("aWay"):
            print '  aWay retrieval 7 is not == Rendered'
            correct = False

        if None != ns.iterNext("aWay"):
            print '  aWay retrieval 8 is not == None'
            correct = False

        # aWay iteration #
        nextVnf = ns.iterNext("bWay")
        print "# starting with Nfpd=bWay"
        if "MECb" != nextVnf:
            print '  bWay retrieval 1 is not == MECa'
            correct = False

        if "WebServer" != ns.iterNext("bWay"):
            print '  bWay retrieval 2 is not == WebServer'
            correct = False

        if "DB" != ns.iterNext("bWay"):
            print '  bWay retrieval 3 is not == DB'
            correct = False

        if "WebServer" != ns.iterNext("bWay"):
            print '  bWay retrieval 4 is not == WebServer'
            correct = False

        if "DB" != ns.iterNext("bWay"):
            print '  bWay retrieval 5 is not == DB'
            correct = False

        if "WebServer" != ns.iterNext("bWay"):
            print '  bWay retrieval 6 is not == WebServer'
            correct = False

        if "Renderer" != ns.iterNext("bWay"):
            print '  bWay retrieval 7 is not == Rendered'
            correct = False

        if None != ns.iterNext("bWay"):
            print '  aWay retrieval 8 is not == None'
            correct = False

        if correct:
            print '  iteration over the NS works properly!'
    def testModifyMappedPath(self):
        """Test the modifyMappedPath method
        :returns: Nothing

        """
        print '######################'
        print '## modifyMappedPath ##'
        print '######################'

        # First NS example
        graph = nx.Graph()
        graph.add_node('start')
        graph.add_node(1)
        graph.add_node(2)
        graph.add_node(3)
        graph.add_edge('start', 1)
        graph.add_edge(1, 2)
        graph.add_edge(2, 3)
        ns = NS.NS()
        ns.setChain(graph)
        ns.setBranchHeads([3])

        mapper = NSM.NsMapper(self.__genMultiDomain())  # the multiDomain does
        # not matter
        mapping = {1: 3, 2: 5, 3: 6}
        path = [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)]

        # Remap VNF1 to server 2
        newPath = mapper.modifyMappedPath(ns, 1, 2, mapping, path, [(0, 1),
                                                                    (1, 2)],
                                          [(2, 3), (3, 4), (4, 'A'), ('A', 5)])
        if newPath == [(0, 1), (1, 2), (2, 3), (3, 4), (4, 'A'), ('A', 5),
                       (5, 6)]:
            print '  first remapping OK!'
        else:
            print '  first mapping BAD!, got newPath=' + str(newPath)

        # Remap VNF2 to server 3
        newPath = mapper.modifyMappedPath(ns, 2, 3, mapping, path, [(3, 3)],
                                          [(3, 4), (4, 'A'), ('A', 'B'),
                                           ('B', 5), (5, 6)])
        if newPath == [(1, 2), (2, 3), (3, 3), (3, 4), (4, 'A'), ('A', 'B'),
                       ('B', 5), (5, 6)]:
            print '  second remapping OK!'
        else:
            print '  second mapping BAD!, got newPath=' + str(newPath)

        # Remap VNF3 to server 7
        newPath = mapper.modifyMappedPath(ns, 3, 7, mapping, path, [(5, 'C'),
                                                                    ('C', 'D'),
                                                                    ('D', 7)],
                                          [])
        if newPath == [(1, 2), (2, 3), (3, 4), (4, 5), (5, 'C'), ('C', 'D'),
                       ('D', 7)]:
            print '  third remapping OK!'
        else:
            print '  third mapping BAD!, got newPath=' + str(newPath)

        # Test if exceptions are risen properly
        errorCatched = False
        try:
            newPath = mapper.modifyMappedPath(ns, 1, 2, mapping, path,
                                              [(0, 1), (1, 5)], [(2, 3),
                                                                 (3, 4),
                                                                 (4, 'A'),
                                                                 ('A', 5)])
        except Exception as e:
            errorCatched = True
            print '  raise last node in prevPath != new server: OK!'
        if not errorCatched:
            print '  raise last node in prevPath != new server: ERR!'

        errorCatched = False
        try:
            newPath = mapper.modifyMappedPath(ns, 1, 2, mapping, path,
                                              [(0, 1), (1, 2)], [(10, 3),
                                                                 (3, 4),
                                                                 (4, 'A'),
                                                                 ('A', 5)])
        except Exception as e:
            errorCatched = True
            print '  raise first node in afterPath!= new server: OK!'
        if not errorCatched:
            print '  raise first node in afterPath!= new server: OK!'

        errorCatched = False
        try:
            newPath = mapper.modifyMappedPath(ns, 2, 3, mapping, path,
                                              [(6, 3)], [(3, 4), (4, 'A'),
                                                         ('A', 'B'), ('B', 5),
                                                         (5, 6)])
        except Exception as e:
            errorCatched = True
            print '  raise first node in prevPath != prev server: OK!'
        if not errorCatched:
            print '  raise first node in prevPath != prev server: OK!'

        errorCatched = False
        try:
            newPath = mapper.modifyMappedPath(ns, 2, 3, mapping, path,
                                              [(3, 3)], [(3, 4), (4, 'A'),
                                                         ('A', 'B'), ('B', 5),
                                                         (5, 8)])
        except Exception as e:
            errorCatched = True
            print '  raise last node in afterPath != next server: OK!'
        if not errorCatched:
            print '  raise last node in afterPath != next server: OK!'

        # Second NS example
        graph = nx.Graph()
        graph.add_node('start')
        graph.add_node(1)
        graph.add_node(2)
        graph.add_edge('start', 1)
        graph.add_edge(1, 2)
        ns = NS.NS()
        ns.setChain(graph)
        ns.setBranchHeads([2])

        mapping = {1: 1, 2: 3}
        path = [(1, 1), (1, 2), (2, 3)]

        # Remap VNF2 to server 1
        newPath = mapper.modifyMappedPath(ns, 2, 1, mapping, path, [(1, 1)],
                                          [])
        if newPath == [(1, 1), (1, 1)]:
            print '  fourth remapping OK!'
        else:
            print '  fourth mapping BAD!, got newPath=' + str(newPath)

        # Remap VNF1 to server 3
        newPath = mapper.modifyMappedPath(ns, 1, 3, mapping, path, [(1, 2),
                                                                    (2, 3)],
                                          [(3, 3)])
        if newPath == [(1, 2), (2, 3), (3, 3)]:
            print '  fifth remapping OK!'
        else:
            print '  fifth mapping BAD!, got newPath=' + str(newPath)
    def testGreedy(self):
        """Tests the greedy mapping algorithm
        :returns: Nothing

        """
        md = self.__genMultiDomain()
        mapper = NSM.NsMapper(md)
        err = False

        print '############'
        print '## greedy ##'
        print '############'

        # Stress test server consumption
        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=10, cpu=1)
        chain.add_node(2, memory=0, disk=10, cpu=1)
        chain.add_edge('start', 1, bw=0, delay=90)
        chain.add_edge(1, 2, bw=0, delay=90)
        ns.setChain(chain)
        ns.setBranchHeads([2])

        nsMapping = mapper.greedy(0, 1, ns)
        if nsMapping.getPath('start', 1) == [(1, 3), (3, 4)] and\
                nsMapping.getPath(1, 2) == [(4, 4)] and\
                nsMapping.getServerMapping(1) == 4 and\
                nsMapping.getServerMapping(2) == 4 and\
                nsMapping.getDelay() == 20:
            print '  first server-stress mapping: OK'
        else:
            print '  first server-stress mapping: ERR'

        ns = NS.NS()  # node 4 can only host one of the VNFs
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=10, cpu=2)
        chain.add_node(2, memory=0, disk=10, cpu=2)
        chain.add_edge('start', 1, bw=0, delay=90)
        chain.add_edge(1, 2, bw=0, delay=90)
        ns.setChain(chain)
        ns.setBranchHeads([2])
        nsMapping = mapper.greedy(0, 1, ns)
        if nsMapping.getPath('start', 1) == [(1, 3), (3, 4)] and\
                nsMapping.getPath(1, 2) == [(4, 5)] and\
                nsMapping.getServerMapping(1) == 4 and\
                nsMapping.getServerMapping(2) == 5 and\
                nsMapping.getDelay() == 26:
            print '  second server-stress mapping: OK\n'
        else:
            print '  second server-stress mapping: ERR'

        mapper.freeMappings()

        # Link stress testing
        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=0, cpu=0)
        chain.add_edge('start', 1, bw=200, delay=90)
        ns.setChain(chain)
        ns.setBranchHeads([1])

        nsMapping = mapper.greedy(0, 1, ns)
        if nsMapping.getPath('start', 1) == [(1, 3), (3, 4)] and\
            nsMapping.getServerMapping(1) == 4 and\
            nsMapping.getDelay() == 20:
            print '  first link-stress mapping: OK'
        else:
            print '  first link-stress mapping: ERR'

        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=0, cpu=4)
        chain.add_node(2, memory=0, disk=0, cpu=1)
        chain.add_edge('start', 1, bw=0, delay=90)
        chain.add_edge(1, 2, bw=250, delay=90)
        ns.setChain(chain)
        ns.setBranchHeads([2])

        nsMapping = mapper.greedy(0, 1, ns)
        if nsMapping.getPath('start', 1) == [(1, 3), (3, 4)] and\
                nsMapping.getPath(1, 2) == [(4, 5)] and\
                nsMapping.getServerMapping(1) == 4 and\
                nsMapping.getServerMapping(2) == 5 and\
                nsMapping.getDelay() == 26:
            print '  second link-stress mapping: OK'
        else:
            print '  second link-stress mapping: ERR'

        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=10, cpu=0)
        chain.add_node(2, memory=0, disk=10, cpu=0)
        chain.add_edge('start', 1, bw=50, delay=90)
        chain.add_edge(1, 2, bw=30000, delay=0)
        ns.setChain(chain)
        ns.setBranchHeads([2])

        nsMapping = mapper.greedy(0, 1, ns)
        if nsMapping.getPath('start', 1) == [(1, 3), (3, 6), (6, 5)] and\
                nsMapping.getPath(1, 2) == [(5, 5)] and\
                nsMapping.getServerMapping(1) == 5 and\
                nsMapping.getServerMapping(2) == 5 and\
                nsMapping.getDelay() == 20:
            print '  third link-stress mapping: OK'
        else:
            print '  third link-stress mapping: ERR'

        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=0, cpu=0)
        chain.add_edge('start', 1, bw=200, delay=19)
        ns.setChain(chain)
        ns.setBranchHeads([1])

        nsMapping = mapper.greedy(0, 1, ns)
        if nsMapping != None:
            print '  fourth link-stress mapping: ERR'
        else:
            print '  fourth link-stress mapping: OK'

        mapper.freeMappings()

        #################################
        ## Test joining VNF in a chain ##
        #################################
        print ''
        md = self.__genSquareMultiDomain()
        ns = NS.NS()
        chain = nx.Graph()
        chain.add_node('start')
        chain.add_node(1, memory=0, disk=51, cpu=4)
        chain.add_node(2, memory=0, disk=52, cpu=3)
        chain.add_node(3, memory=0, disk=53, cpu=2)
        chain.add_node(4, memory=0, disk=54, cpu=1)
        chain.add_edge('start', 1, bw=100, delay=100)
        chain.add_edge(1, 2, bw=100, delay=100)
        chain.add_edge(1, 3, bw=100, delay=100)
        chain.add_edge(3, 4, bw=100, delay=100)
        chain.add_edge(2, 4, bw=100, delay=100)
        ns.setChain(chain)
        ns.setBranchHeads([4])

        mapper = NSM.NsMapper(md)
        nsMapping = mapper.greedy(0, 1, ns)
        link13 = md.getLnkRes(0, 1, 3)
        link12 = md.getLnkRes(0, 1, 2)
        link34 = md.getLnkRes(0, 3, 4)
        link24 = md.getLnkRes(0, 2, 4)
        serv1 = md.getServerRes(0, 1)
        serv2 = md.getServerRes(0, 2)
        serv3 = md.getServerRes(0, 3)
        serv4 = md.getServerRes(0, 4)

        mappingsOk = nsMapping.getServerMapping(1) == 1 and\
                nsMapping.getServerMapping(2) == 2 and\
                nsMapping.getServerMapping(3) == 3 and\
                nsMapping.getServerMapping(4) == 4
        linksOk = link12['bw'] == link13['bw'] == link34['bw'] ==\
                link24['bw'] == 200
        serversOk = serv1['disk'] == serv1['cpu'] ==\
                serv2['disk'] == serv2['cpu'] ==\
                serv3['disk'] == serv3['cpu'] ==\
                serv4['disk'] == serv4['cpu']

        if mappingsOk and linksOk and serversOk:
            print '  joint VNFs mapping: OK!'
        else:
            print '  joint VNFs mapping: ERR!'

        mapper.freeMappings()