makefile
wildcard函数 $(wildcard *.c) : 获取工作目录下的所有.c文件列表
makefile符号表示
https://blog.csdn.net/dlf1769/article/details/78997967
- makefile 代码解析
ifndef的作用是 如果没有传值,则中间内容是定义的默认值 ifdef ;
ifdef 如果变量;的值非空,那到表达式为真。否则,表达式为假。当然,;同样可以是一个函数的返回值。注意,ifdef只是测试一个变量是否有值,其并不会把变量扩展到当前位置。
#新建三个文件夹 分别为
mkdir -p build pcaps logs
#对应makefile中的 %.json:%.p4下的语句
p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4
basic.p4(81): [--Wwarn=unused] warning: Unused action parameter dstAddr
action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
^^^^^^^
basic.p4(81): [--Wwarn=unused] warning: Unused action parameter port
action ipv4_forward(macAddr_t dstAddr, egressSpec_t port) {
# 运行 build的下方语句 ^^^^
sudo python ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc
mkdir -p build pcaps logs
p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4
p4c-bm2-ss --p4v 16 --p4runtime-files build/firewall.p4.p4info.txt -o build/firewall.json firewall.p4
firewall.p4(124): [--Wwarn=unused] warning: bloom_filter_1: unused instance
register<bit<1>>(4096) bloom_filter_1;
^^^^^^^^^^^^^^
firewall.p4(125): [--Wwarn=unused] warning: bloom_filter_2: unused instance
register<bit<1>>(4096) bloom_filter_2;
^^^^^^^^^^^^^^
sudo python ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc
#!/usr/bin/env python2
# Copyright 2013-present Barefoot Networks, Inc.
#
# 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.
#
# Adapted by Robert MacDavid (macdavid@cs.princeton.edu) from scripts found in
# the p4app repository (https://github.com/p4lang/p4app)
#
# We encourage you to dissect this script to better understand the BMv2/Mininet
# environment used by the P4 tutorial.
#
import os, sys, json, subprocess, re, argparse
from time import sleep
from p4_mininet import P4Switch, P4Host
from mininet.net import Mininet
from mininet.topo import Topo
from mininet.link import TCLink
from mininet.cli import CLI
from p4runtime_switch import P4RuntimeSwitch
import p4runtime_lib.simple_controller
def configureP4Switch(**switch_args):
""" Helper class that is called by mininet to initialize
the virtual P4 switches. The purpose is to ensure each
switch's thrift server is using a unique port.
"""
if "sw_path" in switch_args and 'grpc' in switch_args['sw_path']:
# If grpc appears in the BMv2 switch target, we assume will start P4Runtime
class ConfiguredP4RuntimeSwitch(P4RuntimeSwitch):
def __init__(self, *opts, **kwargs):
kwargs.update(switch_args)
P4RuntimeSwitch.__init__(self, *opts, **kwargs)
def describe(self):
print "%s -> gRPC port: %d" % (self.name, self.grpc_port)
return ConfiguredP4RuntimeSwitch
else:
class ConfiguredP4Switch(P4Switch):
next_thrift_port = 9090
def __init__(self, *opts, **kwargs):
global next_thrift_port
kwargs.update(switch_args)
kwargs['thrift_port'] = ConfiguredP4Switch.next_thrift_port
ConfiguredP4Switch.next_thrift_port += 1
P4Switch.__init__(self, *opts, **kwargs)
def describe(self):
print "%s -> Thrift port: %d" % (self.name, self.thrift_port)
return ConfiguredP4Switch
class ExerciseTopo(Topo): # 该类在create_network()中用到
""" The mininet topology class for the P4 tutorial exercises.
"""
def __init__(self, hosts, switches, links, log_dir, bmv2_exe, pcap_dir, **opts):
Topo.__init__(self, **opts)
host_links = []
switch_links = [