summaryrefslogtreecommitdiffstats
path: root/vpp-integration/pom.xml
blob: e74419ad8d8ef3c96fcdb4dc34c84ab3a902c7e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2015 Cisco and/or its affiliates.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at:

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <parent>
        <groupId>io.fd.hc2vpp.common</groupId>
        <artifactId>hc2vpp-parent</artifactId>
        <version>1.19.04-SNAPSHOT</version>
        <relativePath>../common/hc2vpp-parent</relativePath>
    </parent>

    <groupId>io.fd.hc2vpp.integration</groupId>
    <artifactId>vpp-integration</artifactId>
    <name>${project.artifactId}</name>
    <version>1.19.04-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modelVersion>4.0.0</modelVersion>
    <description>Aggregator for Honeycomb's VPP distribution. Aggregating all Hc2vpp plugins.</description>

    <modules>
        <module>minimal-distribution</module>
        <module>api-docs</module>
    </modules>

    <!-- DO NOT install or deploy the repo root pom as it's only needed to initiate a build -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
l.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/usr/bin/env python3

# Copyright (c) 2020 Cisco and/or its affiliates.
#
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
#
# Licensed under the Apache License 2.0 or
# GNU General Public License v2.0 or later;  you may not use this file
# except in compliance with one of these Licenses. You
# may obtain a copy of the Licenses at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#     https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
#
# Note: If this file is linked with Scapy, which is GPLv2+, your use of it
# must be under GPLv2+.  If at any point in the future it is no longer linked
# with Scapy (or other GPLv2+ licensed software), you are free to choose Apache 2.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Traffic script for NAT verification."""

import sys

import ipaddress

from scapy.layers.inet import IP, TCP, UDP
from scapy.layers.inet6 import IPv6, ICMPv6ND_NS
from scapy.layers.l2 import Ether
from scapy.packet import Raw

from .PacketVerifier import RxQueue, TxQueue
from .TrafficScriptArg import TrafficScriptArg


def valid_ipv4(ip):
    try:
        ipaddress.IPv4Address(ip)
        return True
    except (AttributeError, ipaddress.AddressValueError):
        return False


def valid_ipv6(ip):
    try:
        ipaddress.IPv6Address(ip)
        return True
    except (AttributeError, ipaddress.AddressValueError):
        return False


def main():
    """Send, receive and check IP/IPv6 packets with UDP/TCP layer passing
    through NAT.
    """
    args = TrafficScriptArg(
        [
            u"tx_src_mac", u"rx_dst_mac", u"src_ip_in", u"src_ip_out",
            u"dst_ip", u"tx_dst_mac", u"rx_src_mac", u"protocol",
            u"src_port_in", u"src_port_out", u"dst_port"
        ]
    )

    tx_src_mac = args.get_arg(u"tx_src_mac")
    tx_dst_mac = args.get_arg(u"tx_dst_mac")
    rx_dst_mac = args.get_arg(u"rx_dst_mac")
    rx_src_mac = args.get_arg(u"rx_src_mac")
    src_ip_in = args.get_arg(u"src_ip_in")
    src_ip_out = args.get_arg(u"src_ip_out")
    dst_ip = args.get_arg(u"dst_ip")
    protocol = args.get_arg(u"protocol")
    sport_in = int(args.get_arg(u"src_port_in"))
    try:
        sport_out = int(args.get_arg(u"src_port_out"))
    except ValueError:
        sport_out = None
    dst_port = int(args.get_arg(u"dst_port"))

    tx_txq = TxQueue(args.get_arg(u"tx_if"))
    tx_rxq = RxQueue(args.get_arg(u"tx_if"))
    rx_txq = TxQueue(args.get_arg(u"rx_if"))
    rx_rxq = RxQueue(args.get_arg(u"rx_if"))

    sent_packets = list()
    pkt_raw = Ether(src=tx_src_mac, dst=tx_dst_mac)

    if valid_ipv4(src_ip_in) and valid_ipv4(dst_ip):
        ip_layer = IP
    elif valid_ipv6(src_ip_in) and valid_ipv6(dst_ip):
        ip_layer = IPv6
    else:
        raise ValueError(u"IP not in correct format")
    pkt_raw /= ip_layer(src=src_ip_in, dst=dst_ip)

    if protocol == u"UDP":
        pkt_raw /= UDP(sport=sport_in, dport=dst_port)
        proto_layer = UDP
    elif protocol == u"TCP":
        # flags=0x2 => SYN flag set
        pkt_raw /= TCP(sport=sport_in, dport=dst_port, flags=0x2)
        proto_layer = TCP
    else:
        raise ValueError(u"Incorrect protocol")

    pkt_raw /= Raw()
    sent_packets.append(pkt_raw)
    tx_txq.send(pkt_raw)

    while True:
        ether = rx_rxq.recv(2)

        if ether is None:
            raise RuntimeError(u"IP packet Rx timeout")

        if ether.haslayer(ICMPv6ND_NS):
            # read another packet in the queue if the current one is ICMPv6ND_NS
            continue
        else:
            # otherwise process the current packet
            break

    if rx_dst_mac != ether[Ether].dst or rx_src_mac != ether[Ether].src:
        raise RuntimeError(f"Matching packet unsuccessful: {ether!r}")

    ip_pkt = ether.payload
    if not isinstance(ip_pkt, ip_layer):
        raise RuntimeError(f"Not an {ip_layer!s} packet received: {ip_pkt!r}")
    if ip_pkt.src != src_ip_out:
        raise RuntimeError(
            f"Matching Src IP address unsuccessful: "
            f"{src_ip_out} != {ip_pkt.src}"
        )
    if ip_pkt.dst != dst_ip:
        raise RuntimeError(
            f"Matching Dst IP address unsuccessful: {dst_ip} != {ip_pkt.dst}"
        )

    proto_pkt = ip_pkt.payload
    if not isinstance(proto_pkt, proto_layer):
        raise RuntimeError(
            f"Not a {proto_layer!s} packet received: {proto_pkt!r}"
        )
    if sport_out is not None:
        if proto_pkt.sport != sport_out:
            raise RuntimeError(
                f"Matching Src {proto_layer!s} port unsuccessful: "
                f"{sport_out} != {proto_pkt.sport}"
            )
    else:
        sport_out = proto_pkt.sport
    if proto_pkt.dport != dst_port:
        raise RuntimeError(
            f"Matching Dst {proto_layer!s} port unsuccessful: "
            f"{dst_port} != {proto_pkt.dport}"
        )
    if proto_layer == TCP:
        if proto_pkt.flags != 0x2:
            raise RuntimeError(
                f"Not a TCP SYN packet received: {proto_pkt!r}"
            )

    pkt_raw = Ether(src=rx_dst_mac, dst=rx_src_mac)
    pkt_raw /= ip_layer(src=dst_ip, dst=src_ip_out)
    pkt_raw /= proto_layer(sport=dst_port, dport=sport_out)
    if proto_layer == TCP:
        # flags=0x12 => SYN, ACK flags set
        pkt_raw[TCP].flags = 0x12
    pkt_raw /= Raw()
    rx_txq.send(pkt_raw)

    while True:
        ether = tx_rxq.recv(2, ignore=sent_packets)

        if ether is None:
            raise RuntimeError(u"IP packet Rx timeout")

        if ether.haslayer(ICMPv6ND_NS):
            # read another packet in the queue if the current one is ICMPv6ND_NS
            continue
        else:
            # otherwise process the current packet
            break

    if ether[Ether].dst != tx_src_mac or ether[Ether].src != tx_dst_mac:
        raise RuntimeError(f"Matching packet unsuccessful: {ether!r}")

    ip_pkt = ether.payload
    if not isinstance(ip_pkt, ip_layer):
        raise RuntimeError(f"Not an {ip_layer!s} packet received: {ip_pkt!r}")
    if ip_pkt.src != dst_ip:
        raise RuntimeError(
            f"Matching Src IP address unsuccessful: {dst_ip} != {ip_pkt.src}"
        )
    if ip_pkt.dst != src_ip_in:
        raise RuntimeError(
            f"Matching Dst IP address unsuccessful: {src_ip_in} != {ip_pkt.dst}"
        )

    proto_pkt = ip_pkt.payload
    if not isinstance(proto_pkt, proto_layer):
        raise RuntimeError(
            f"Not a {proto_layer!s} packet received: {proto_pkt!r}"
        )
    if proto_pkt.sport != dst_port:
        raise RuntimeError(
            f"Matching Src {proto_layer!s} port unsuccessful: "
            f"{dst_port} != {proto_pkt.sport}"
        )
    if proto_pkt.dport != sport_in:
        raise RuntimeError(
            f"Matching Dst {proto_layer!s} port unsuccessful: "
            f"{sport_in} != {proto_pkt.dport}"
        )
    if proto_layer == TCP:
        if proto_pkt.flags != 0x12:
            raise RuntimeError(
                f"Not a TCP SYN-ACK packet received: {proto_pkt!r}"
            )

    sys.exit(0)


if __name__ == u"__main__":
    main()