Esempio n. 1
0
    def test_seen_new_mac_new_vlan_new_ip(self, notify_new_MAC_session,
                                          notify_new_VLAN_session,
                                          notify_new_IP_session):
        response = session.seen(mac='aa:bb:cc:dd:ee:01',
                                vlan='eth0.1',
                                ip='1.2.3.4')

        self.assertEqual(response, (True, True, True))
        self.assertEqual(notify_new_MAC_session.call_count, 0)
        self.assertEqual(notify_new_VLAN_session.call_count, 0)
        self.assertEqual(notify_new_IP_session.call_count, 1)
        self.assertTrue(session.is_online(mac='aa:bb:cc:dd:ee:01'))
        self.assertTrue(
            session.is_online(mac='aa:bb:cc:dd:ee:01', vlan='eth0.1'))
        self.assertTrue(
            session.is_online(mac='aa:bb:cc:dd:ee:01',
                              vlan='eth0.1',
                              ip='1.2.3.4'))

        response = session.seen(mac='aa:bb:cc:dd:ee:01',
                                vlan='eth0.1',
                                ip='1.2.3.4')

        self.assertEqual(response, (False, False, False))
        self.assertEqual(notify_new_MAC_session.call_count, 0)
        self.assertEqual(notify_new_VLAN_session.call_count, 0)
        self.assertEqual(notify_new_IP_session.call_count, 1)  # Not changed
Esempio n. 2
0
    def test_end(self, notify_end_IP_session, notify_end_VLAN_session,
                 notify_end_MAC_session):
        session.seen(mac='aa:bb:cc:dd:ee:01', vlan='eth0.1', ip='1.2.3.1')
        session.seen(mac='aa:bb:cc:dd:ee:02', vlan='eth0.2', ip='1.2.3.2')
        session.seen(mac='aa:bb:cc:dd:ee:03', vlan='eth0.3', ip='1.2.3.3')

        session.end(mac='aa:bb:cc:dd:ee:01')

        self.assertFalse(session.is_online('aa:bb:cc:dd:ee:01'))
        self.assertFalse(session.is_online('aa:bb:cc:dd:ee:01', vlan='eth0.1'))
        self.assertFalse(
            session.is_online('aa:bb:cc:dd:ee:01', vlan='eth0.1',
                              ip='1.2.3.1'))
        self.assertEqual(notify_end_MAC_session.call_count, 1)

        session.end(mac='aa:bb:cc:dd:ee:02', vlan='eth0.2')

        self.assertTrue(session.is_online('aa:bb:cc:dd:ee:02'))
        self.assertFalse(session.is_online('aa:bb:cc:dd:ee:02', vlan='eth0.2'))
        self.assertFalse(
            session.is_online('aa:bb:cc:dd:ee:02', vlan='eth0.2',
                              ip='1.2.3.2'))
        self.assertEqual(notify_end_VLAN_session.call_count, 1)

        session.end(mac='aa:bb:cc:dd:ee:03', vlan='eth0.3', ip='1.2.3.3')

        self.assertTrue(session.is_online('aa:bb:cc:dd:ee:03'))
        self.assertTrue(session.is_online('aa:bb:cc:dd:ee:03', vlan='eth0.3'))
        self.assertFalse(
            session.is_online('aa:bb:cc:dd:ee:03', vlan='eth0.3',
                              ip='1.2.3.3'))
        self.assertEqual(notify_end_IP_session.call_count, 1)
Esempio n. 3
0
    def test_seen_known_mac_new_vlan(self, notify_new_MAC_session,
                                     notify_new_VLAN_session,
                                     notify_new_IP_session):
        session.seen(mac='aa:bb:cc:dd:ee:01')
        notify_new_MAC_session.reset_mock()

        response = session.seen(mac='aa:bb:cc:dd:ee:01', vlan='eth0.1')

        self.assertEqual(response, (False, True, False))
        self.assertEqual(notify_new_MAC_session.call_count, 0)
        self.assertEqual(notify_new_VLAN_session.call_count, 1)
        self.assertEqual(notify_new_IP_session.call_count, 0)
        self.assertTrue(session.is_online(mac='aa:bb:cc:dd:ee:01'))
        self.assertTrue(
            session.is_online(mac='aa:bb:cc:dd:ee:01', vlan='eth0.1'))
Esempio n. 4
0
    def test_seen_new_mac(self, notify_new_MAC_session,
                          notify_new_VLAN_session, notify_new_IP_session,
                          notify_MAC_port):
        response = session.seen(mac='aa:bb:cc:dd:ee:01')

        self.assertEqual(response, (True, False, False))
        self.assertEqual(notify_new_MAC_session.call_count, 1)
        self.assertEqual(notify_new_VLAN_session.call_count, 0)
        self.assertEqual(notify_new_IP_session.call_count, 0)
        self.assertEqual(notify_MAC_port.call_count, 0)
        self.assertTrue(session.is_online(mac='aa:bb:cc:dd:ee:01'))
Esempio n. 5
0
    def test_seen_with_port(self, notify_MAC_port, notify_end_MAC_session):
        self.assertIsNone(session.mac_port('aa:bb:cc:dd:ee:01'))

        session.seen(mac='aa:bb:cc:dd:ee:01',
                     port={
                         'local_id': 1,
                         'interface': 'i1'
                     })

        self.assertTrue(session.is_online(mac='aa:bb:cc:dd:ee:01'))
        self.assertEqual(session.mac_port('aa:bb:cc:dd:ee:01'), {
            'local_id': 1,
            'interface': 'i1'
        })
        self.assertEqual(notify_MAC_port.call_count, 0)
        self.assertEqual(notify_end_MAC_session.call_count, 0,
                         'No session end on same port')

        session.seen(mac='aa:bb:cc:dd:ee:01',
                     port={
                         'local_id': 1,
                         'interface': 'i2'
                     })

        self.assertEqual(session.mac_port('aa:bb:cc:dd:ee:01'), {
            'local_id': 1,
            'interface': 'i2'
        })
        self.assertEqual(notify_MAC_port.call_count, 0)
        self.assertEqual(notify_end_MAC_session.call_count, 1,
                         'session ended on change of port')

        session.seen(mac='aa:bb:cc:dd:ee:01',
                     port={
                         'local_id': 1,
                         'interface': None
                     })

        self.assertEqual(session.mac_port('aa:bb:cc:dd:ee:01'), {
            'local_id': 1,
            'interface': 'i2'
        })
        self.assertEqual(notify_MAC_port.call_count, 0)
        self.assertEqual(notify_end_MAC_session.call_count, 1,
                         'Session end on port change')

        session.seen(mac='aa:bb:cc:dd:ee:01',
                     port={
                         'local_id': 2,
                         'interface': None,
                         'ssid': 'SSID'
                     })

        self.assertEqual(session.mac_port('aa:bb:cc:dd:ee:01'), {
            'local_id': 2,
            'interface': None,
            'ssid': 'SSID'
        })
        self.assertEqual(notify_MAC_port.call_count, 0)
        self.assertEqual(notify_end_MAC_session.call_count, 2,
                         'No session end on same port')

        session.seen(mac='aa:bb:cc:dd:ee:01',
                     port={
                         'local_id': 2,
                         'interface': 'i3'
                     })

        self.assertEqual(session.mac_port('aa:bb:cc:dd:ee:01'), {
            'local_id': 2,
            'interface': 'i3',
            'ssid': 'SSID'
        })
        self.assertEqual(notify_MAC_port.call_count, 1)
        self.assertEqual(notify_end_MAC_session.call_count, 2,
                         'No session end on same port')