Esempio n. 1
0
    def test_serialize(self):
        pkt = packet.Packet()

        eth_pkt = ethernet.ethernet("b0:a8:6e:18:b8:08", "64:87:88:e9:cb:c8")
        pkt.add_protocol(eth_pkt)

        ip_pkt = ipv4.ipv4(src="172.28.3.1", dst="172.28.3.2", tos=192, identification=26697, proto=inet.IPPROTO_UDP)
        pkt.add_protocol(ip_pkt)

        udp_pkt = udp.udp(49152, 3784)
        pkt.add_protocol(udp_pkt)

        bfd_pkt = bfd.bfd(
            ver=1,
            diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
            state=bfd.BFD_STATE_UP,
            detect_mult=3,
            my_discr=6,
            your_discr=7,
            desired_min_tx_interval=60000,
            required_min_rx_interval=60000,
            required_min_echo_rx_interval=0,
        )
        pkt.add_protocol(bfd_pkt)

        eq_(len(pkt.protocols), 4)

        pkt.serialize()
        eq_(pkt.data, self.data)
Esempio n. 2
0
    def test_serialize_with_auth_sha1(self):
        pkt = packet.Packet()

        eth_pkt = ethernet.ethernet("08:00:27:d1:95:7c", "08:00:27:ed:54:41")
        pkt.add_protocol(eth_pkt)

        ip_pkt = ipv4.ipv4(src="192.168.57.2", dst="192.168.57.1", tos=192, identification=2960, proto=inet.IPPROTO_UDP)
        pkt.add_protocol(ip_pkt)

        udp_pkt = udp.udp(49152, 3784)
        pkt.add_protocol(udp_pkt)

        auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16817, auth_key=self.auth_keys[2])

        bfd_pkt = bfd.bfd(
            ver=1,
            diag=bfd.BFD_DIAG_NO_DIAG,
            flags=bfd.BFD_FLAG_AUTH_PRESENT,
            state=bfd.BFD_STATE_DOWN,
            detect_mult=3,
            my_discr=1,
            your_discr=0,
            desired_min_tx_interval=1000000,
            required_min_rx_interval=1000000,
            required_min_echo_rx_interval=0,
            auth_cls=auth_cls,
        )

        pkt.add_protocol(bfd_pkt)

        eq_(len(pkt.protocols), 4)

        pkt.serialize()
        eq_(pkt.data, self.data_auth_sha1)
Esempio n. 3
0
    def test_serialize_with_auth_sha1(self):
        pkt = packet.Packet()

        eth_pkt = ethernet.ethernet('08:00:27:d1:95:7c', '08:00:27:ed:54:41')
        pkt.add_protocol(eth_pkt)

        ip_pkt = ipv4.ipv4(src='192.168.57.2', dst='192.168.57.1', tos=192,
                           identification=2960, proto=inet.IPPROTO_UDP)
        pkt.add_protocol(ip_pkt)

        udp_pkt = udp.udp(49152, 3784)
        pkt.add_protocol(udp_pkt)

        auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16817,
                                 auth_key=self.auth_keys[2])

        bfd_pkt = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_NO_DIAG,
                          flags=bfd.BFD_FLAG_AUTH_PRESENT,
                          state=bfd.BFD_STATE_DOWN, detect_mult=3, my_discr=1,
                          your_discr=0, desired_min_tx_interval=1000000,
                          required_min_rx_interval=1000000,
                          required_min_echo_rx_interval=0,
                          auth_cls=auth_cls)

        pkt.add_protocol(bfd_pkt)

        eq_(len(pkt.protocols), 4)

        pkt.serialize()
        eq_(pkt.data, self.data_auth_sha1)
Esempio n. 4
0
    def test_serialize(self):
        pkt = packet.Packet()

        eth_pkt = ethernet.ethernet('b0:a8:6e:18:b8:08', '64:87:88:e9:cb:c8')
        pkt.add_protocol(eth_pkt)

        ip_pkt = ipv4.ipv4(src='172.28.3.1',
                           dst='172.28.3.2',
                           tos=192,
                           identification=26697,
                           proto=inet.IPPROTO_UDP)
        pkt.add_protocol(ip_pkt)

        udp_pkt = udp.udp(49152, 3784)
        pkt.add_protocol(udp_pkt)

        bfd_pkt = bfd.bfd(ver=1,
                          diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
                          state=bfd.BFD_STATE_UP,
                          detect_mult=3,
                          my_discr=6,
                          your_discr=7,
                          desired_min_tx_interval=60000,
                          required_min_rx_interval=60000,
                          required_min_echo_rx_interval=0)
        pkt.add_protocol(bfd_pkt)

        eq_(len(pkt.protocols), 4)

        pkt.serialize()
        eq_(pkt.data, self.data)
Esempio n. 5
0
    def test_serialize_with_auth_simple(self):
        pkt = packet.Packet()

        eth_pkt = ethernet.ethernet('08:00:27:d1:95:7c', '08:00:27:ed:54:41')
        pkt.add_protocol(eth_pkt)

        ip_pkt = ipv4.ipv4(src='192.168.57.2', dst='192.168.57.1', tos=192,
                           identification=3216, proto=inet.IPPROTO_UDP)
        pkt.add_protocol(ip_pkt)

        udp_pkt = udp.udp(49152, 3784)
        pkt.add_protocol(udp_pkt)

        auth_cls = bfd.SimplePassword(auth_key_id=2,
                                      password=self.auth_keys[2])

        bfd_pkt = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_NO_DIAG,
                          flags=bfd.BFD_FLAG_AUTH_PRESENT,
                          state=bfd.BFD_STATE_DOWN, detect_mult=3, my_discr=1,
                          your_discr=0, desired_min_tx_interval=1000000,
                          required_min_rx_interval=1000000,
                          required_min_echo_rx_interval=0,
                          auth_cls=auth_cls)

        pkt.add_protocol(bfd_pkt)

        eq_(len(pkt.protocols), 4)

        pkt.serialize()
        eq_(pkt.data, self.data_auth_simple)
Esempio n. 6
0
    def bfd_packet(src_mac,
                   dst_mac,
                   src_ip,
                   dst_ip,
                   ipv4_id,
                   src_port,
                   dst_port,
                   diag=0,
                   state=0,
                   flags=0,
                   detect_mult=0,
                   my_discr=0,
                   your_discr=0,
                   desired_min_tx_interval=0,
                   required_min_rx_interval=0,
                   required_min_echo_rx_interval=0,
                   auth_cls=None):
        """
        Generate BFD packet with Ethernet/IPv4/UDP encapsulated.
        """
        # Generate ethernet header first.
        pkt = packet.Packet()
        eth_pkt = ethernet.ethernet(dst_mac, src_mac, ETH_TYPE_IP)
        pkt.add_protocol(eth_pkt)

        # IPv4 encapsulation
        # set ToS to 192 (Network control/CS6)
        # set TTL to 255 (RFC5881 Section 5.)
        ipv4_pkt = ipv4.ipv4(proto=inet.IPPROTO_UDP,
                             src=src_ip,
                             dst=dst_ip,
                             tos=192,
                             identification=ipv4_id,
                             ttl=255)
        pkt.add_protocol(ipv4_pkt)

        # UDP encapsulation
        udp_pkt = udp.udp(src_port=src_port, dst_port=dst_port)
        pkt.add_protocol(udp_pkt)

        # BFD payload
        bfd_pkt = bfd.bfd(
            ver=1,
            diag=diag,
            state=state,
            flags=flags,
            detect_mult=detect_mult,
            my_discr=my_discr,
            your_discr=your_discr,
            desired_min_tx_interval=desired_min_tx_interval,
            required_min_rx_interval=required_min_rx_interval,
            required_min_echo_rx_interval=required_min_echo_rx_interval,
            auth_cls=auth_cls)
        pkt.add_protocol(bfd_pkt)

        pkt.serialize()
        return pkt.data
Esempio n. 7
0
    def test_json(self):
        bfd1 = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
                       state=bfd.BFD_STATE_UP, detect_mult=3, my_discr=6,
                       your_discr=7, desired_min_tx_interval=60000,
                       required_min_rx_interval=60000,
                       required_min_echo_rx_interval=0)

        jsondict = bfd1.to_jsondict()
        bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
        eq_(str(bfd1), str(bfd2))
Esempio n. 8
0
    def test_json(self):
        bfd1 = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_CTRL_DETECT_TIME_EXPIRED,
                       state=bfd.BFD_STATE_UP, detect_mult=3, my_discr=6,
                       your_discr=7, desired_min_tx_interval=60000,
                       required_min_rx_interval=60000,
                       required_min_echo_rx_interval=0)

        jsondict = bfd1.to_jsondict()
        bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
        eq_(str(bfd1), str(bfd2))
Esempio n. 9
0
    def bfd_packet(
        src_mac,
        dst_mac,
        src_ip,
        dst_ip,
        ipv4_id,
        src_port,
        dst_port,
        diag=0,
        state=0,
        flags=0,
        detect_mult=0,
        my_discr=0,
        your_discr=0,
        desired_min_tx_interval=0,
        required_min_rx_interval=0,
        required_min_echo_rx_interval=0,
        auth_cls=None,
    ):
        """
        Generate BFD packet with Ethernet/IPv4/UDP encapsulated.
        """
        # Generate ethernet header first.
        pkt = packet.Packet()
        eth_pkt = ethernet.ethernet(dst_mac, src_mac, ETH_TYPE_IP)
        pkt.add_protocol(eth_pkt)

        # IPv4 encapsulation
        # set ToS to 192 (Network control/CS6)
        # set TTL to 255 (RFC5881 Section 5.)
        ipv4_pkt = ipv4.ipv4(proto=inet.IPPROTO_UDP, src=src_ip, dst=dst_ip, tos=192, identification=ipv4_id, ttl=255)
        pkt.add_protocol(ipv4_pkt)

        # UDP encapsulation
        udp_pkt = udp.udp(src_port=src_port, dst_port=dst_port)
        pkt.add_protocol(udp_pkt)

        # BFD payload
        bfd_pkt = bfd.bfd(
            ver=1,
            diag=diag,
            state=state,
            flags=flags,
            detect_mult=detect_mult,
            my_discr=my_discr,
            your_discr=your_discr,
            desired_min_tx_interval=desired_min_tx_interval,
            required_min_rx_interval=required_min_rx_interval,
            required_min_echo_rx_interval=required_min_echo_rx_interval,
            auth_cls=auth_cls,
        )
        pkt.add_protocol(bfd_pkt)

        pkt.serialize()
        return pkt.data
Esempio n. 10
0
    def test_json_with_auth_sha1(self):
        auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16859,
                                 auth_key=self.auth_keys[2])

        bfd1 = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_NO_DIAG,
                       flags=bfd.BFD_FLAG_AUTH_PRESENT,
                       state=bfd.BFD_STATE_DOWN, detect_mult=3, my_discr=1,
                       your_discr=0, desired_min_tx_interval=1000000,
                       required_min_rx_interval=1000000,
                       required_min_echo_rx_interval=0,
                       auth_cls=auth_cls)

        jsondict = bfd1.to_jsondict()
        bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
        eq_(str(bfd1), str(bfd2))
Esempio n. 11
0
    def test_json_with_auth_sha1(self):
        auth_cls = bfd.KeyedSHA1(auth_key_id=2, seq=16859,
                                 auth_key=self.auth_keys[2])

        bfd1 = bfd.bfd(ver=1, diag=bfd.BFD_DIAG_NO_DIAG,
                       flags=bfd.BFD_FLAG_AUTH_PRESENT,
                       state=bfd.BFD_STATE_DOWN, detect_mult=3, my_discr=1,
                       your_discr=0, desired_min_tx_interval=1000000,
                       required_min_rx_interval=1000000,
                       required_min_echo_rx_interval=0,
                       auth_cls=auth_cls)

        jsondict = bfd1.to_jsondict()
        bfd2 = bfd.bfd.from_jsondict(jsondict['bfd'])
        eq_(str(bfd1), str(bfd2))
Esempio n. 12
0
    def test_json_with_auth_simple(self):
        auth_cls = bfd.SimplePassword(auth_key_id=2, password=self.auth_keys[2])

        bfd1 = bfd.bfd(
            ver=1,
            diag=bfd.BFD_DIAG_NO_DIAG,
            flags=bfd.BFD_FLAG_AUTH_PRESENT,
            state=bfd.BFD_STATE_DOWN,
            detect_mult=3,
            my_discr=1,
            your_discr=0,
            desired_min_tx_interval=1000000,
            required_min_rx_interval=1000000,
            required_min_echo_rx_interval=0,
            auth_cls=auth_cls,
        )

        jsondict = bfd1.to_jsondict()
        bfd2 = bfd.bfd.from_jsondict(jsondict["bfd"])
        eq_(str(bfd1), str(bfd2))