Пример #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 += bytes(messages[key])
        message = bytes([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' % (flow[0], message[0]))
        if len(flow) != flow[0] + 1:
            self.fail('invalid size for message')
Пример #2
0
class FakeNeighbor(object):
    description = 'a test neighbor'
    router_id = RouterID('127.0.0.1')
    local_address = IPv4('127.0.0.1')
    peer_address = IPv4('127.0.0.1')
    host_name = 'localhost'
    domain_name = 'localdomain'
    peer_as = ASN('65500')
    local_as = ASN('65500')
    hold_time = HoldTime(180)
    asn4 = False
    add_path = 0
    extended_message = False
    nexthop = None

    # capability
    route_refresh = False
    graceful_restart = False
    multisession = None
    add_path = None
    aigp = None
    operational = None

    @staticmethod
    def families():
        return NLRI.known_families()
Пример #3
0
 def __init__(self):
     self.update({
         'description': 'a test neighbor',
         'router-id': RouterID('127.0.0.1'),
         'local-address': IPv4('127.0.0.1'),
         'peer-address': IPv4('127.0.0.1'),
         'host-name': 'localhost',
         'domain-name': 'localdomain',
         'peer-as': ASN('65500'),
         'local-as': ASN('65500'),
         'hold-time': HoldTime(180),
         'capability': {
             'asn4': False,
             'add-path': 0,
             'extended_message': False,
             'nexthop': None,
             'route-refresh': False,
             'graceful-restart': False,
             'multi-session': None,
             'add-path': None,
             'aigp': None,
             'operational': None,
             'extended-message': True,
         },
     })
Пример #4
0
 def __init__(self, local, remote, asn, peer):
     self['local-address'] = IPv4(local)
     self['peer_address'] = IPv4(remote)
     self['peer-as'] = ASN(asn)
     self['local-as'] = ASN(peer)
     self['capability'] = {
         'asn4': True,
     }
Пример #5
0
    def __init__(self, data):
        self.type = PeerType(ord(data[2]))
        self.flag = PeerFlag(ord(data[3]))
        self.distinguisher = unpack('!L', data[4:8])[0]
        self.asn = unpack('!L', data[28:32])[0]
        self.id = IPv4.unpack(data[32:36])

        if self.flag.ipv4(): self.peer_address = IPv4.unpack(data[24:28])
        if self.flag.ipv6(): self.peer_address = IPv6.unpack(data[12:28])
Пример #6
0
	def __init__ (self,data):
		self.type = PeerType(ord(data[2]))
		self.flag = PeerFlag(ord(data[3]))
		self.distinguisher = unpack('!L',data[4:8])[0]
		self.asn = unpack('!L',data[28:32])[0]
		self.id = IPv4.unpack(data[32:36])

		if self.flag.ipv4(): self.peer_address = IPv4.unpack(data[24:28])
		if self.flag.ipv6(): self.peer_address = IPv6.unpack(data[12:28])
Пример #7
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 = bytes(messages[key])
Пример #8
0
 def __init__(self, ip, number, transitive=True, community=None):
     self.ip = ip
     self.number = number
     # assert(number < pow(2,16))
     RouteTarget.__init__(
         self, community if community else pack(
             '!2s4sH', self._subtype(transitive), IPv4.pton(ip), number))
Пример #9
0
 def __init__(self, asn, ip, transitive, community=None):
     self.asn = asn
     self.ip = ip
     Origin.__init__(
         self,
         community if community else pack('!2sH4s', self._subtype(), asn,
                                          IPv4.pton(ip)))
Пример #10
0
 def __init__(self, asn, ip, transitive, community=None):
     self.ip = ip
     self.asn = asn
     RouteTarget.__init__(
         self, community if community else pack(
             '!2s4sH', self._packedTypeSubtype(transitive), IPv4.pton(ip),
             asn))
Пример #11
0
 def __init__(self, asn, ip, transitive, community=None):
     self.asn = asn
     self.ip = ip
     Origin.__init__(
         self, community if community else pack(
             '!BBH4s', self.COMMUNITY_TYPE
             | 0x40 if transitive else self.COMMUNITY_TYPE, 0x02, asn,
             IPv4.pton(ip)))
Пример #12
0
 def __init__(self, asn, ip, transitive, community=None):
     self.ip = ip
     self.asn = asn
     RouteTarget.__init__(
         self, community if community else pack(
             '!BB4sH', self.COMMUNITY_TYPE
             | 0x40 if transitive else self.COMMUNITY_TYPE, 0x02,
             IPv4.pton(ip), asn))
Пример #13
0
 def __init__(self, ip, number, transitive=True, community=None):
     self.ip = ip
     self.number = number
     assert (number < pow(2, 16))
     RouteTarget.__init__(
         self, community if community else pack(
             '!BB4sH', self.COMMUNITY_TYPE
             | Attribute.Flag.TRANSITIVE if transitive else
             self.COMMUNITY_TYPE, 0x02, IPv4.pton(ip), number))
Пример #14
0
	def __init__ (self, asn, ip, transitive, community=None):
		self.ip = ip
		self.asn = asn
		RouteTarget.__init__(
			self,
			community if community else pack(
				'!2s4sH',
				self._packedTypeSubtype(transitive),
				IPv4.pton(ip),asn
			)
		)
Пример #15
0
	def __init__ (self, asn, ip, transitive, community=None):
		self.ip = ip
		self.asn = asn
		RouteTarget.__init__(
			self,
			community if community else pack(
				'!BB4sH',
				self.COMMUNITY_TYPE | 0x40 if transitive else self.COMMUNITY_TYPE,0x02,
				IPv4.pton(ip),asn
			)
		)
Пример #16
0
	def __init__ (self, asn, ip, transitive, community=None):
		self.asn = asn
		self.ip = ip
		Origin.__init__(
			self,
			community if community else pack(
				'!2sH4s',
				self._packedTypeSubtype(),
				asn,
				IPv4.pton(ip)
			)
		)
Пример #17
0
	def __init__ (self, asn, ip, transitive, community=None):
		self.ip = ip
		self.asn = asn
		Origin.__init__(
			self,
			community if community else pack(
				'!2s4sH',
				self._subtype(),
				IPv4.pton(ip),
				asn
			)
		)
Пример #18
0
class Neighbor:
    description = 'a test neighbor'
    router_id = RouterID('127.0.0.1')
    local_address = IPv4('127.0.0.1')
    peer_address = IPv4('127.0.0.1')
    peer_as = ASN('65500')
    local_as = ASN('65500')
    hold_time = HoldTime(180)
    asn4 = False
    add_path = 0

    # capability
    route_refresh = False
    graceful_restart = False
    multisession = None
    add_path = None
    aigp = None

    @staticmethod
    def families():
        return known_families()
Пример #19
0
	def __init__ (self, ip, number, transitive=True, community=None):
		self.ip = ip
		self.number = number
		# assert(number < pow(2,16))
		RouteTarget.__init__(
			self,
			community if community else pack(
				'!2s4sH',
				self._subtype(transitive),
				IPv4.pton(ip),number
			)
		)
Пример #20
0
	def __init__ (self, ip, number, transitive=True, community=None):
		self.ip = ip
		self.number = number
		assert(number < pow(2,16))
		RouteTarget.__init__(
			self,
			community if community else pack(
				'!BB4sH',
				self.COMMUNITY_TYPE | Attribute.Flag.TRANSITIVE if transitive else self.COMMUNITY_TYPE,0x02,
				IPv4.pton(ip),number
			)
		)
Пример #21
0
	def __init__ (self, asn, ip, transitive, community=None):
		self.asn = asn
		self.ip = ip
		Origin.__init__(
			self,
			community if community else pack(
				'!BBH4s',
				self.COMMUNITY_TYPE | 0x40 if transitive else self.COMMUNITY_TYPE,0x02,
				asn,
				IPv4.pton(ip)
			)
		)
Пример #22
0
    def test_compare(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),
            'anyport_3': FlowAnyPort(NumericOperator.EQ, 80),
        }

        flow1 = Flow()
        for key in ['destination', 'source', 'anyport_1', 'anyport_2']:
            flow1.add(components[key])

        flow2 = Flow()
        for key in ['destination', 'source', 'anyport_3']:
            flow2.add(components[key])

        if flow1 != flow1:
            self.fail('the flows are the same')

        if flow1 == flow2:
            self.fail('the flows are not the same')
Пример #23
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 += bytes(messages[key])
        message = bytes([len(message)]) + message
        # flow.add(to_FlowAction(65000,False,False))
        flow.pack()
Пример #24
0
	def unpack (cls, data, negotiated):
		clusters = []
		while data:
			clusters.append(IPv4.unpack(data[:4]))
			data = data[4:]
		return cls(clusters)
Пример #25
0
	def unpack (data):
		ip,asn = unpack('!4sH',data[2:8])
		return OriginIPASN(IPv4.ntop(ip),ASN(asn),False,data[:8])
Пример #26
0
 def unpack(data):
     ip, bit = unpack('!4sH', data[2:8])
     return TrafficNextHopIPv4IETF(IPv4.ntop(ip), bool(bit & 0x01),
                                   data[:8])
Пример #27
0
 def unpack(data):
     asn, ip = unpack('!H4s', data[2:8])
     return OriginASNIP(ASN(asn), IPv4.ntop(ip), False, data[:8])
Пример #28
0
	def __init__ (self, ip, label=0,flags=0,tunnel=None):
		self.ip = ip  # looks like a bad name
		PMSI.__init__(self,tunnel if tunnel else IPv4.pton(ip),label,flags)
Пример #29
0
 def unpack(cls, data):
     ip, number = unpack('!4sH', data[2:8])
     return cls(IPv4.ntop(ip), number, False, data[:8])
Пример #30
0
 def __init__(self, ip, label=0, flags=0, tunnel=None):
     self.ip = ip  # looks like a bad name
     PMSI.__init__(self, tunnel if tunnel else IPv4.pton(ip), label, flags)
Пример #31
0
 def unpack(cls, data, negotiated):
     clusters = []
     while data:
         clusters.append(IPv4.unpack(data[:4]))
         data = data[4:]
     return cls(clusters)
Пример #32
0
 def __init__(self, ip):
     IPv4.__init__(self, ip)
Пример #33
0
Файл: rt.py Проект: asnd/exabgp
	def unpack (data):
		ip,asn = unpack('!4sH',data[2:8])
		return RouteTargetIPASN(IPv4.ntop(ip),ASN(asn),False,data[:8])
Пример #34
0
	def unpack (cls, data):
		ip,number = unpack('!4sH',data[2:8])
		return cls(IPv4.ntop(ip),number,False,data[:8])
Пример #35
0
 def __init__(self, local, remote, asn, peer):
     self.local_address = IPv4(local)
     self.peer_address = IPv4(remote)
     self.peer_as = ASN(asn)
     self.local_as = ASN(peer)
Пример #36
0
 def unpack(data):
     ip, asn = unpack('!4sH', data[2:8])
     return RouteTargetIPASN(IPv4.ntop(ip), ASN(asn), False, data[:8])
Пример #37
0
	def unpack (cls, data, negotiated):
		if negotiated.asn4:
			return cls(ASN.unpack(data[:4]),IPv4.unpack(data[-4:]))
		return cls(ASN.unpack(data[:2]),IPv4.unpack(data[-4:]))
Пример #38
0
	def unpack (cls,data,negotiated):
		if negotiated.asn4:
			return cls(ASN.unpack(data[:4]),IPv4.unpack(data[-4:]))
		return cls(ASN.unpack(data[:2]),IPv4.unpack(data[-4:]))
Пример #39
0
	def __init__ (self, ip, packed=None):
		if IPv4.toafi(ip) != AFI.ipv4:
			raise ValueError('wrong address family')
		IPv4.__init__(self,ip,packed)
Пример #40
0
	def unpack (cls, data, negotiated):
		return IPv4.unpack(data,cls)
Пример #41
0
	def __init__ (self,ip,label=0,flags=0,tunnel=None):
		self.ip = ip
		PMSI.__init__(self,tunnel if tunnel else IPv4.pton(ip),label,flags)
Пример #42
0
Файл: rt.py Проект: asnd/exabgp
	def unpack(data):
		asn,ip = unpack('!H4s',data[2:8])
		return RouteTargetASNIP(ASN(asn),IPv4.ntop(ip),False,data[:8])
Пример #43
0
 def __init__(self, ip, label=0, flags=0, tunnel=None):
     self.ip = ip
     PMSI.__init__(self, tunnel if tunnel else IPv4.pton(ip), label, flags)
Пример #44
0
 def unpack(cls, data, negotiated):
     return IPv4.unpack(data, cls)
Пример #45
0
	def unpack (data):
		ip,number = unpack('!4sH',data[2:8])
		return RouteTargetIPNumber(IPv4.ntop(ip),number,False,data[:8])
Пример #46
0
	def unpack (cls,tunnel,label,flags):
		ip = IPv4.ntop(tunnel)
		return cls(ip,label,flags,tunnel)
Пример #47
0
 def unpack(cls, data, direction, negotiated):
     return IPv4.unpack(data, cls)
Пример #48
0
 def unpack(data):
     ip, asn = unpack('!4sH', data[2:8])
     return OriginIPASN(IPv4.ntop(ip), ASN(asn), False, data[:8])
Пример #49
0
	def __init__ (self, ip):
		IPv4.__init__(self,ip)
Пример #50
0
 def unpack(cls, tunnel, label, flags):
     ip = IPv4.ntop(tunnel)
     return cls(ip, label, flags, tunnel)
Пример #51
0
	def unpack (data):
		asn,ip = unpack('!H4s',data[2:8])
		return OriginASNIP(ASN(asn),IPv4.ntop(ip),False,data[:8])