forked from blizzardplus/p4-nat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·71 lines (59 loc) · 2.26 KB
/
run.sh
File metadata and controls
executable file
·71 lines (59 loc) · 2.26 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# 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.
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $THIS_DIR/env.sh
P4C_BM_SCRIPT=$P4C_BM_PATH/p4c_bm/__main__.py
SWITCH_PATH=$BMV2_PATH/targets/simple_switch/simple_switch
CLI_PATH=$BMV2_PATH/targets/simple_switch/sswitch_CLI
# Probably not very elegant but it works nice here: we enable interactive mode
# to be able to use fg. We start the switch in the background, sleep for 2
# minutes to give it time to start, then add the entries and put the switch
# process back in the foreground
set -m
rm simple_router.json
$P4C_BM_SCRIPT simple_router.p4 --json simple_router.json
# This gets root permissions, and gives libtool the opportunity to "warm-up"
sudo $SWITCH_PATH >/dev/null 2>&1
if [ "$#" -ne 1 ]; then
echo "Error!! Usage: ./run.sh [router|switch]"
exit 1
fi
if [ $1 = "router" ]; then
CLI_PATH=$BMV2_PATH/targets/simple_router/runtime_CLI
sudo python ./mininet/1sw_demo.py --behavioral-exe \
/home/p4/Desktop/repos/p4-nat/p4-nat/simple_router \
--json /home/p4/Desktop/repos/p4-nat/p4-nat/simple_router.json &
sleep 2
$CLI_PATH < commands.txt
echo "READY!!!"
fg
elif [ $1 = "switch" ]; then
sudo ./tools/veth_teardown.sh
sudo ./tools/veth_setup.sh
sudo $SWITCH_PATH simple_router.json \
-i 0@veth0 -i 1@veth2 -i 2@veth4 -i 3@veth6 -i 4@veth8 \
--nanolog ipc:///tmp/bm-0-log.ipc \
--debugger \
--pcap &
sleep 2
$CLI_PATH simple_router.json < commands.txt
echo "READY!!!"
fg
else
echo "Error!! Usage: ./run.sh [router|switch]"
exit 1
fi
## OLD command
#sudo ./simple_router -i 0@veth1 -i 1@veth3 -i 2@veth5 -i 3@veth7 --pcap simple_router.json