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')
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])
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)))
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))
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))
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)))
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))
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))
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 ) )
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 ) )
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) ) )
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 ) )
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 ) )
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 ) )
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) ) )
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()
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')
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)
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)
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)
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)