Beispiel #1
0
    def setUp(self):
        super().setUp()
        self.device_id = 0
        self.election_id = (0, 1)

        self.servicer = P4RuntimeServicer()
        self.servicer.Write = Mock(spec=[], return_value=p4runtime_pb2.WriteResponse())
        self.servicer.Read = Mock(spec=[], return_value=p4runtime_pb2.ReadResponse())
        p4runtime_pb2_grpc.add_P4RuntimeServicer_to_server(self.servicer, self.server)

        sh.setup(device_id=self.device_id,
                 grpc_addr=self.grpc_addr,
                 election_id=self.election_id,
                 config=sh.FwdPipeConfig(self._p4info_path, self._config_path))
import p4runtime_sh.shell as sh
import p4runtime_sh.context as context
import json

sh.setup(
    device_id=1,
    grpc_addr='bmv2:50001',
    election_id=(0, 1), # (high, low)
    config=sh.FwdPipeConfig('/p4build/p4info.txt', '/p4build/bmv2.json')
)
print("successful setup!")

UE   = 0
ENODEB = 1
SPGW = 2
INTERNET = 3
            #  UE,        ENODEB        SPGW       INTERNET
PORTS       = ["1",       "1",          None,      "2"]
NEXT_IDS    = ["1",       "1",          None,      "2"]
IPV4_ADDRS  = ["1.0.0.1", "140.0.0.1", "140.0.0.2", "3.0.0.1"]

TEID = str(0xabcd)
SDF_RULE_ID = "1"
PCC_RULE_ID = "1"

FWD_IPV4_UNICAST = "2"
ETHERTYPE_IPV4 = str(0x0800)
SPGW_DIR_UNKNOWN = "0"
SPGW_DIR_UPLINK = "1"
SPGW_DIR_DOWNLINK = "2"
PCC_GATE_OPEN = "0"
import p4runtime_sh.shell as sh

# you can omit the config argument if the switch is already configured with the
# correct P4 dataplane.
sh.setup(device_id=1,
         grpc_addr='172.17.0.2:50001',
         election_id=(1, 0),
         config=sh.FwdPipeConfig('mri.p4.p4info.txt', 'mri.json'))

# see p4runtime_sh/test.py for more examples
te = table_entry["MyEgress.swtrace"](action="MyEgress.add_swtrace")
te.action["swid"] = ("1")
te.insert()

te = table_entry["MyIngress.ipv4_lpm"](action="MyIngress.ipv4_forward")
te.match["hdr.ipv4.dstAddr"] = ("10.0.0.1")
te.action["dstAddr"] = ("7a:da:30:9f:7b:a2")
te.action["port"] = ("1")
te.insert()

te = table_entry["MyIngress.ipv4_lpm"](action="MyIngress.ipv4_forward")
te.match["hdr.ipv4.dstAddr"] = ("10.0.0.2")
te.action["dstAddr"] = ("f6:4e:94:ee:0d:cd")
te.action["port"] = ("2")
te.insert()
# ...

sh.teardown()
Beispiel #4
0
                        type=int,
                        required=False,
                        default=0,
                        help='The device ID (default 0)')
    parser.add_argument('-n',
                        '--table-name',
                        help='The table name to clean',
                        type=str,
                        required=True)
    return parser.parse_args()


if __name__ == '__main__':
    """
    Clears all entries from a P4 table
    """
    args = get_args()
    logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

    logger.info('Connecting to switch at [%s]', args.grpc_addr)
    sh.setup(device_id=args.dev_id, grpc_addr=args.grpc_addr)

    logger.info('Retrieving table entry - [%s]', args.table_name)
    table_entry = sh.TableEntry(args.table_name)
    logger.info('Table entry to clear - [%s]', table_entry)
    table_entry.read(lambda te: logger.info('Deleting - [%s]', te))
    table_entry.read(lambda te: te.delete())
    logger.info('Table [%s] cleared', args.table_name)

    sh.teardown()
Beispiel #5
0
standard_frequency = 10
connection_set = [False]

# ======================================#
'''
This is the P4Runtime shell-related setup. We are using p4runtime-shell
open-souce code from the git found at https://github.com/p4lang/p4runtime-shell
and installed on the lab's Collector.
the setup & teardown should only be done once!
'''
if not connection_set[0]:
    shell_lock.acquire()
    try:
        sh.setup(device_id=0,
                 grpc_addr='132.68.36.62:50051',
                 election_id=(0, 1),
                 config=sh.FwdPipeConfig('/tmp/OurMirror.p4info',
                                         '/tmp/OurMirror.bin'))
        te = sh.TableEntry('control_out_port.ipv4_check_checksum')(
            action='DoMirror')
        connection_set[0] = True
        print("connection acomplished")
    finally:
        shell_lock.release()

# ======================================#


def clear():
    # for windows
    if name == 'nt':