def test_DiagramTree__subnetCreation_basic(self):
        config = testutil.makeToyTopoConfig(
            ['r0', 'r1', 'r2'],  # routers
            ['s1', 's2', 's3', 's4'],  # switches
            ['h1', 'h2', 'h3', 'h4', 'h5'],  # hosts

            # links
            [('r0', 'r1'), ('r0', 'r2'), ('r1', 'r2'), ('r1', 's1'),
             ('r2', 's2'), ('s2', 's3'), ('s2', 's4'), ('s3', 's4'),
             ('s1', 'h1'), ('s3', 'h2'), ('s3', 'h3'), ('s4', 'h4'),
             ('s4', 'h5')])
        graph = DiagramGraph(config)
        tree = graph.getDiagramTree()
        fr = tree.freeNodes

        self.assertEqual(len(tree.routers), 3)
        self.assertEqual(len(tree.subnets), 2)

        if len(tree.subnets[0].switches) > 1:
            (bigSbntIdx, smallSbntIdx) = (0, 1)
        else:
            (bigSbntIdx, smallSbntIdx) = (1, 0)

        self.assertEqual(len(tree.subnets[smallSbntIdx].switches), 1)
        self.assertEqual(len(tree.subnets[smallSbntIdx].hosts), 1)
        self.assertEqual(len(tree.subnets[bigSbntIdx].switches), 3)
        self.assertEqual(len(tree.subnets[bigSbntIdx].hosts), 4)
        self.assertEqual(
            len(fr['routers']) + len(fr['switches']) + len(fr['hosts']), 0)
        self.assertEqual(len(tree.primaryLinks), 11)
        self.assertEqual(len(tree.secondaryLinks), 2)
        self.assertEqual(len(tree.redundantLinks), 26)
        self.assertEqual(len(tree.unusedLinks), 0)
Exemple #2
0
    def test_DiagramGraph__badCreation_noDevices(self):
        config = testutil.makeToyTopoConfig(
            [],  # routers
            [],  # switches
            [],  # hosts
            []  # links
        )

        with self.assertRaises(DiagramGraphError) as cm:
            DiagramGraph(config)
        self.assertEqual(cm.exception.message, 'network is missing devices')
Exemple #3
0
    def test_DiagramGraph__routersCreation_badLink(self):
        config = testutil.makeToyTopoConfig(
            ['r1', 'r2', 'r3'],  # routers
            [],  # switches
            [],  # hosts
            [('r1', 'r0')]  # links
        )

        with self.assertRaises(DiagramGraphError) as cm:
            DiagramGraph(config)
        self.assertEqual(cm.exception.message,
                         'Device r0 not found in Graph devices')
Exemple #4
0
    def test_DiagramGraph__routersCreation_dupLink(self):
        config = testutil.makeToyTopoConfig(
            ['r1', 'r2', 'r3'],  # routers
            [],  # switches
            [],  # hosts
            [('r1', 'r2'), ('r1', 'r2')]  # links
        )
        graph = DiagramGraph(config)

        self.assertEqual(len(graph.devices.keys()), 3)
        self.assertEqual(len(graph.devices['r1'].neighbors), 1)
        self.assertEqual(len(graph.devices['r2'].neighbors), 1)
        self.assertEqual(len(graph.devices['r3'].neighbors), 0)
Exemple #5
0
    def test_DiagramGraph__basicCreation_host(self):
        config = testutil.makeToyTopoConfig(
            [],  # routers
            [],  # switches
            ['h'],  # hosts
            []  # links
        )
        graph = DiagramGraph(config)

        self.assertIsNone(graph.root)
        self.assertEqual(len(graph.devices.keys()), 1)
        self.assertEqual(graph.devices['h'].deviceName, 'h')
        self.assertEqual(graph.devices['h'].deviceType, DeviceType.HOST)
Exemple #6
0
    def test_DiagramGraph__basicCreation_router(self):
        config = testutil.makeToyTopoConfig(
            ['r'],  # routers
            [],  # switches
            [],  # hosts
            []  # links
        )
        graph = DiagramGraph(config)

        self.assertTrue(hasattr(graph, 'root'))
        self.assertEqual(graph.devices['r'], graph.root)
        self.assertEqual(graph.root.deviceType, DeviceType.ROUTER)
        self.assertEqual(graph.root.deviceName, 'r')
        self.assertEqual(len(graph.devices.keys()), 1)
Exemple #7
0
    def test_DiagramGraph__routersCreation_routerHost(self):
        config = testutil.makeToyTopoConfig(
            ['r1'],  # routers
            [],  # switches
            ['h1'],  # hosts
            [('r1', 'h1')]  # links
        )

        with self.assertRaises(DiagramGraphError) as cm:
            DiagramGraph(config)
        self.assertEqual(
            cm.exception.message,
            'Device type ROUTER cannot be neighbors with HOST (Entity: r1 [ROUTER, 0 neighbors])'
        )
    def test_DiagramTree__basicCreation_router(self):
        config = testutil.makeToyTopoConfig(
            ['r'],  # routers
            [],  # switches
            [],  # hosts
            []  # links
        )
        graph = DiagramGraph(config)
        tree = graph.getDiagramTree()
        fr = tree.freeNodes

        self.assertEqual(len(tree.routers), 1)
        self.assertEqual(len(tree.subnets), 0)
        self.assertEqual(
            len(fr['routers']) + len(fr['switches']) + len(fr['hosts']), 0)
        self.assertEqual(len(tree.primaryLinks), 0)
        self.assertEqual(len(tree.secondaryLinks), 0)
        self.assertEqual(len(tree.redundantLinks), 0)
        self.assertEqual(len(tree.unusedLinks), 0)