def test_flow_trace_hop_no_transformed_flow(): """Test we don't crash on missing or None values.""" FlowTraceHop({ 'edge': { 'node1': 'dummy', 'node1interface': 'eth0', 'node2': 'router1', 'node2interface': 'Ethernet1' }, 'filterIn': None, 'filterOut': None, 'routes': [ 'StaticRoute<0.0.0.0/0,nhip:10.192.48.1,nhint:eth0>_fnhip:10.192.48.1' ], 'transformedFlow': None }) FlowTraceHop({ 'edge': { 'node1': 'dummy', 'node1interface': 'eth0', 'node2': 'router1', 'node2interface': 'Ethernet1' }, 'filterIn': None, 'filterOut': None, 'routes': [ 'StaticRoute<0.0.0.0/0,nhip:10.192.48.1,nhint:eth0>_fnhip:10.192.48.1' ] })
def testFlowTraceHopDeserialization_noRoutes(): hopDict = { "edge": { "node1": "node1", "node1interface": "Ethernet9", "node2": "(none)", "node2interface": "null_interface" } } hop = FlowTraceHop(hopDict) # check deserialization assert hop.routes == []
def testFlowTraceHopDeserialization(): hopDict = { "edge": { "node1": "node1", "node1interface": "Ethernet9", "node2": "(none)", "node2interface": "null_interface" }, "routes": [ "BgpRoute<12.10.16.8/25,nhip:9.1.1.2,nhint:dynamic>_fnhip:9.1.1.2" ], "transformedFlow": { "dscp": 0, "dstIp": "2.1.1.1", "dstPort": 0, "ecn": 0, "fragmentOffset": 0, "icmpCode": 255, "icmpVar": 255, "ingressNode": "ingress", "ingressVrf": "default", "ipProtocol": "IP", "packetLength": 0, "srcIp": "5.5.1.1", "srcPort": 0, "state": "NEW", "tag": "BASE", "tcpFlagsAck": 0, "tcpFlagsCwr": 0, "tcpFlagsEce": 0, "tcpFlagsFin": 0, "tcpFlagsPsh": 0, "tcpFlagsRst": 0, "tcpFlagsSyn": 0, "tcpFlagsUrg": 0 } } hop = FlowTraceHop(hopDict) hopStr = str(hop) # check deserialization assert hop.edge assert len(hop.routes) == 1 assert hop.transformedFlow # check the string representation has the essential elements (without forcing a strict format) assert str(hop.edge) in hopStr assert str(hop.routes[0]) in hopStr assert str(hop.transformedFlow) in hopStr
def __init__(self, dictionary): self.disposition = dictionary["disposition"] self.flowTraceHops = [FlowTraceHop(hop) for hop in dictionary.get("hops", [])] self.notes = dictionary["notes"]