예제 #1
0
def test_hop_repr_str():
    hop = Hop(
        "node1",
        [
            Step(EnterInputIfaceStepDetail("in_iface1", "in_vrf1"), "SENT_IN"),
            Step(
                RoutingStepDetail(
                    [
                        {
                            "network": "1.1.1.1/24",
                            "protocol": "bgp",
                            "nextHopIp": "1.2.3.4",
                        },
                        {
                            "network": "1.1.1.2/24",
                            "protocol": "static",
                            "nextHopIp": "1.2.3.5",
                        },
                    ],
                    "12.123.1.2",
                    "iface1",
                ),
                "FORWARDED",
            ),
            Step(FilterStepDetail("preSourceNat_filter", "PRENAT", "", ""),
                 "PERMITTED"),
            Step(ExitOutputIfaceStepDetail("out_iface1", None), "SENT_OUT"),
        ],
    )

    assert (
        str(hop) == "node: node1\n  SENT_IN(in_iface1)\n"
        "  FORWARDED(ARP IP: 12.123.1.2, Output Interface: iface1, Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4),static (Network: 1.1.1.2/24, Next Hop IP:1.2.3.5)])\n  "
        "PERMITTED(preSourceNat_filter (PRENAT))\n  SENT_OUT(out_iface1)")
예제 #2
0
def test_hop_repr_str():
    hop = Hop(
        "node1",
        [
            Step(EnterInputIfaceStepDetail("in_iface1", "in_vrf1"), "SENT_IN"),
            Step(
                RoutingStepDetail(
                    [
                        RouteInfo("bgp", "1.1.1.1/24", NextHopIp("1.2.3.4"),
                                  None, 1, 1),
                        RouteInfo("static", "1.1.1.2/24", NextHopIp("1.2.3.5"),
                                  None, 1, 1),
                    ],
                    ForwardedOutInterface("iface1", "12.123.1.2"),
                    "12.123.1.2",
                    "iface1",
                ),
                "FORWARDED",
            ),
            Step(FilterStepDetail("preSourceNat_filter", "PRENAT", "", ""),
                 "PERMITTED"),
            Step(ExitOutputIfaceStepDetail("out_iface1", None), "SENT_OUT"),
        ],
    )

    assert (
        str(hop) == "node: node1\n  SENT_IN(in_iface1)\n"
        "  FORWARDED(Forwarded out interface: iface1 with resolved next-hop IP: 12.123.1.2, Routes: [bgp (Network: 1.1.1.1/24, Next Hop: ip 1.2.3.4),static (Network: 1.1.1.2/24, Next Hop: ip 1.2.3.5)])\n  "
        "PERMITTED(preSourceNat_filter (PRENAT))\n  SENT_OUT(out_iface1)")
예제 #3
0
def test_transformation_step_detail_str():
    no_diffs = TransformationStepDetail("type", [])
    one_diff = TransformationStepDetail("type", [FlowDiff("field", "old", "new")])
    two_diffs = TransformationStepDetail("type",
                                         [FlowDiff("field1", "old1", "new1"),
                                          FlowDiff("field2", "old2", "new2")])

    step = Step(no_diffs, "ACTION")
    assert str(step) == "ACTION(type)"

    step = Step(one_diff, "ACTION")
    assert str(step) == "ACTION(type field: old -> new)"

    step = Step(two_diffs, "ACTION")
    assert str(step) == "ACTION(type field1: old1 -> new1, field2: old2 -> new2)"
예제 #4
0
def test_hop_repr_str():
    hop = Hop("node1", [
        Step(
            EnterInputIfaceStepDetail("in_iface1", "in_vrf1", "in_filter1"),
            "SENT_IN"),
        Step(RoutingStepDetail(
            [{"network": "1.1.1.1/24", "protocol": "bgp",
              "nextHopIp": "1.2.3.4"},
             {"network": "1.1.1.2/24", "protocol": "static",
              "nextHopIp": "1.2.3.5"}]), "FORWARDED"),
        Step(ExitOutputIfaceStepDetail("out_iface1", "out_filter1", None),
             "SENT_OUT")
    ])

    assert str(
        hop) == "node: node1\n  SENT_IN(in_iface1: in_filter1)\n  FORWARDED(Routes: bgp [Network: 1.1.1.1/24, Next Hop IP:1.2.3.4],static [Network: 1.1.1.2/24, Next Hop IP:1.2.3.5])\n  SENT_OUT(out_iface1: out_filter1)"
예제 #5
0
def test_delivered_step_detail_str():
    detail = DeliveredStepDetail("iface", "1.1.1.1")

    step = Step(detail, "ACTION")
    assert str(
        step
    ) == "ACTION(Output Interface: iface, Resolved Next Hop IP: 1.1.1.1)"
예제 #6
0
def test_arp_error_step_detail_str():
    detail = ArpErrorStepDetail("iface", "1.1.1.1")

    step = Step(detail, "ACTION")
    assert str(
        step
    ) == "ACTION(Output Interface: iface, Resolved Next Hop IP: 1.1.1.1)"
예제 #7
0
def test_exit_output_iface_step_detail_str():
    detail = ExitOutputIfaceStepDetail("iface", None)

    step = Step(detail, "ACTION")
    assert str(step) == "ACTION(iface)"
예제 #8
0
def test_no_route():
    step = Step(RoutingStepDetail([]), "NO_ROUTE")
    assert str(step) == "NO_ROUTE"
예제 #9
0
def test_LoopStep_from_dict():
    step = Step.from_dict({"type": "Loop", "action": "LOOP", "detail": {}})
    assert step.action == "LOOP"
    assert step.detail == LoopStepDetail()
예제 #10
0
def test_no_route_legacy():
    step = Step(RoutingStepDetail([], None, None, None), "NO_ROUTE")
    assert str(step) == "NO_ROUTE"
예제 #11
0
def test_no_route():
    step = Step(RoutingStepDetail([], Discarded(), None, None), "NO_ROUTE")
    assert str(step) == "NO_ROUTE(Discarded)"