Exemplo n.º 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)")
Exemplo n.º 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)")
Exemplo n.º 3
0
def test_only_routes_str_legacy():
    routingStepDetail = RoutingStepDetail(
        [RouteInfo("bgp", "1.1.1.1/24", None, "1.2.3.4", 1, 1)],
        None,
        None,
        None,
    )

    assert (str(routingStepDetail) ==
            "Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4)]")
Exemplo n.º 4
0
def test_no_arp_ip_str():
    routingStepDetail = RoutingStepDetail(
        [{"network": "1.1.1.1/24", "protocol": "bgp", "nextHopIp": "1.2.3.4"}],
        None,
        "iface1",
    )
    assert (
        str(routingStepDetail)
        == "Output Interface: iface1, Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4)]"
    )
Exemplo n.º 5
0
def test_no_output_iface_str():
    routingStepDetail = RoutingStepDetail(
        [{"network": "1.1.1.1/24", "protocol": "bgp", "nextHopIp": "1.2.3.4"}],
        "1.2.3.4",
        None,
    )
    assert (
        str(routingStepDetail)
        == "ARP IP: 1.2.3.4, Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4)]"
    )
Exemplo n.º 6
0
def test_no_arp_ip_str_legacy():
    routingStepDetail = RoutingStepDetail(
        [RouteInfo("bgp", "1.1.1.1/24", None, "1.2.3.4", 1, 1)],
        None,
        None,
        "iface1",
    )
    assert (
        str(routingStepDetail) ==
        "Output Interface: iface1, Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4)]"
    )
Exemplo n.º 7
0
def test_no_output_iface_str_legacy():
    routingStepDetail = RoutingStepDetail(
        [RouteInfo("bgp", "1.1.1.1/24", None, "1.2.3.4", 1, 1)],
        None,
        "1.2.3.4",
        None,
    )
    assert (
        str(routingStepDetail) ==
        "ARP IP: 1.2.3.4, Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4)]"
    )
Exemplo n.º 8
0
def test_only_routes_str():
    routingStepDetail = RoutingStepDetail(
        [{"network": "1.1.1.1/24", "protocol": "bgp", "nextHopIp": "1.2.3.4"}],
        None,
        None,
    )

    assert (
        str(routingStepDetail)
        == "Routes: [bgp (Network: 1.1.1.1/24, Next Hop IP:1.2.3.4)]"
    )
Exemplo n.º 9
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)"
Exemplo n.º 10
0
def test_no_route():
    step = Step(RoutingStepDetail([]), "NO_ROUTE")
    assert str(step) == "NO_ROUTE"
Exemplo n.º 11
0
def test_no_route_legacy():
    step = Step(RoutingStepDetail([], None, None, None), "NO_ROUTE")
    assert str(step) == "NO_ROUTE"
Exemplo n.º 12
0
def test_no_route():
    step = Step(RoutingStepDetail([], Discarded(), None, None), "NO_ROUTE")
    assert str(step) == "NO_ROUTE(Discarded)"