Esempio n. 1
0
    def test_nlri(self):
        components = {
            'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24),
            'source': Flow4Source(IPv4.pton("10.1.2.0"), 24),
            'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT,
                                     25),
            'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT,
                                     80),
        }
        messages = {
            'destination': [0x01, 0x18, 0xc0, 0x00, 0x02],
            'source': [0x02, 0x18, 0x0a, 0x01, 0x02],
            'anyport_1': [0x04, 0x43, 0x19],
            'anyport_2': [0x85, 0x50],
        }

        flow = Flow()
        message = b""
        for key in ['destination', 'source', 'anyport_1', 'anyport_2']:
            flow.add(components[key])
            message += data_from_body(messages[key])
        message = character(len(message)) + message
        # policy.add(to_FlowAction(65000,False,False))
        flow = flow.pack()
        if message[0] != flow[0]:
            self.fail('size mismatch %s %s\n' %
                      (ordinal(flow[0]), ordinal(message[0])))
        if len(flow) != ordinal(flow[0]) + 1:
            self.fail('invalid size for message')
Esempio n. 2
0
    def test_rule(self):
        components = {
            'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24),
            'source': Flow4Source(IPv4.pton("10.1.2.0"), 24),
            'anyport_1': FlowAnyPort(NumericOperator.EQ, 25),
        }
        messages = {
            'destination': [0x01, 0x18, 0xc0, 0x00, 0x02],
            'source': [0x02, 0x18, 0x0a, 0x01, 0x02],
            'anyport_1': [0x04, 0x01, 0x19],
        }

        for key in ['destination', 'source', 'anyport_1']:
            component = components[key].pack()
            message = data_from_body(messages[key])
Esempio n. 3
0
	def test_1_open (self):
		check_capa = {
			1: [(AFI.ipv4, SAFI.unicast), (AFI.ipv6, SAFI.unicast)],
			2: RouteRefresh(),
			65: 65534,
			128: RouteRefresh(),
		}

		message_id = 1
		negotiated = {'invalid':'test'}

		o = Message.unpack(message_id,data_from_body(open_body),negotiated)

		self.assertEqual(o.version,4)
		self.assertEqual(o.asn,65534)
		self.assertEqual(o.router_id,RouterID('0.0.0.0'))
		self.assertEqual(o.hold_time,180)
		for k,v in o.capabilities.items():
			self.assertEqual(v,check_capa[k])
Esempio n. 4
0
    def test_1_open(self):
        check_capa = {
            1: [(AFI.ipv4, SAFI.unicast), (AFI.ipv6, SAFI.unicast)],
            2: RouteRefresh(),
            65: 65534,
            128: RouteRefresh(),
        }

        message_id = 1
        negotiated = {'invalid': 'test'}

        o = Message.unpack(message_id, data_from_body(open_body), negotiated)

        self.assertEqual(o.version, 4)
        self.assertEqual(o.asn, 65534)
        self.assertEqual(o.router_id, RouterID('0.0.0.0'))
        self.assertEqual(o.hold_time, 180)
        for k, v in o.capabilities.items():
            self.assertEqual(v, check_capa[k])
Esempio n. 5
0
    def test_rule_and(self):
        components = {
            'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24),
            'source': Flow4Source(IPv4.pton("10.1.2.0"), 24),
            'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT,
                                     25),
            'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT,
                                     80),
        }
        messages = {
            'destination': [0x01, 0x18, 0xc0, 0x00, 0x02],
            'source': [0x02, 0x18, 0x0a, 0x01, 0x02],
            'anyport_1': [0x04, 0x43, 0x19],
            'anyport_2': [0x04, 0x85, 0x50],
        }

        flow = Flow()
        message = b""
        for key in ['destination', 'source', 'anyport_1', 'anyport_2']:
            flow.add(components[key])
            message += data_from_body(messages[key])
        message = character(len(message)) + message
        # flow.add(to_FlowAction(65000,False,False))
        flow.pack()
Esempio n. 6
0
 def test_decoding_udpate_asn4(self):
     for asn4, body in bodies:
         if not asn4:
             continue
         Update.unpack_message(data_from_body(body), self.negotiated[asn4])
Esempio n. 7
0
	def test_decoding_udpate_asn4 (self):
		for asn4,body in bodies:
			if not asn4:
				continue
			Update.unpack_message(data_from_body(body),self.negotiated[asn4])