Skip to content

Commit

Permalink
Feature/custom faux mac prefix (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
henry54809 authored Jul 15, 2021
1 parent 6119be0 commit 2ffdfc2
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ jobs:
- name: run python tests
run: testing/python_test test_fot
- name: setup fot stack
run: bin/setup_stack devices 5 skip-conn-check dhcp fot
run: bin/setup_stack devices 5 faux-mac-prefix "9a:99:57:1e" skip-conn-check dhcp fot
- name: run fot integration tests
run: timeout 20m bin/run_test_set fot
- name: setup vxlan stack
run: bin/setup_stack devices 5 skip-conn-check dhcp fot vxlan
run: bin/setup_stack devices 5 faux-mac-prefix "9a:99:57:1e" skip-conn-check dhcp fot vxlan
- name: run vxlan integration tests
run: timeout 20m bin/run_test_set fot
- name: setup dts
run: bin/setup_stack devices 5 skip-conn-check dhcp fot dts localhost
run: bin/setup_stack devices 5 faux-mac-prefix "9a:99:57:1e" skip-conn-check dhcp fot dts localhost
- name: run dts integration tests
run: timeout 20m bin/run_test_set fot
- name: post-run logs
Expand Down
2 changes: 1 addition & 1 deletion bin/run_controller
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ if [ -n "$gauge_prom_pt" ]; then
fi

forch_port="-p 500$faucet_id:9019"
docker_envs="--env RUN_MODE=$run_mode"
docker_envs="--env RUN_MODE=$run_mode --env CLEAN_MAC_PREFIX=$CLEAN_MAC_PREFIX"

if [[ -n $vxlan ]]; then
# Extract the local src IP address that can be used as return address.
Expand Down
12 changes: 7 additions & 5 deletions bin/run_faux
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

ROOT=$(realpath $(dirname $0)/..)
postfix=
intf_mac=9a:02:57:1e:8f:00
docker_args=
container_prefix=forch-faux
image=forch/faux
net_opt=--net=none
port_num=0

source bin/stack_functions
set_faux_mac_prefix

intf_mac=$FAUX_MAC_PREFIX:8f:00
cd $ROOT

# If the first argument is a number, then it's a port designation.
Expand All @@ -22,10 +25,9 @@ if [ $# -gt 0 ] && [ $(($1)) -gt 0 -o "$1" == 0 ]; then
mac_port_num=$port_num
fi
postfix=-$port_num
intf_mac=9a:02:57:1e:$(printf %02x $mac_prefix):$(printf %02x $mac_port_num)
intf_mac=$FAUX_MAC_PREFIX:$(printf %02x $mac_prefix):$(printf %02x $mac_port_num)
shift
fi

FAUX_ARGS="$*"

# Check that image exists so docker doesn't pull down random one from dockerhub
Expand All @@ -42,14 +44,14 @@ fi

docker_args="$docker_args -e LOCAL_IF=$realintf -e FAUX_NUM=$port_num"

cid=$(docker run -d --privileged --name $CONTAINER --hostname $CONTAINER $net_opt $docker_args $image ./start_faux $FAUX_ARGS)
cid=$(docker run -d --privileged --name $CONTAINER --hostname $CONTAINER $net_opt $docker_args $image ./start_faux $FAUX_ARGS "faux-mac-prefix=$FAUX_MAC_PREFIX" )
pid=$(docker inspect --format="{{ .State.Pid }}" $cid)

intf=faux$postfix
echo Removing old interface $intf
sudo ip link del $intf 2>/dev/null || true

echo Adding new interface to $pid...
echo Adding new interface $intf_mac to $pid...
sudo ip link add $intf type veth peer name faux-eth0 addr $intf_mac netns $pid
sudo ip link set $intf up

Expand Down
1 change: 1 addition & 0 deletions bin/setup_scale
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ if [ -n "$1" ]; then
fi

source bin/stack_functions
set_faux_mac_prefix

###########################################################

Expand Down
9 changes: 9 additions & 0 deletions bin/setup_stack
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ if [ "$1" == "devices" ]; then
shift 2
fi

if [ "$1" == "faux-mac-prefix" ]; then
export FAUX_MAC_PREFIX="$2"
shift 2
fi

if [ "$1" == "switches" ]; then
switches=$2
shift 2
Expand Down Expand Up @@ -89,6 +94,7 @@ fi

rm -rf tcpdump # Clean out directory
source bin/stack_functions
set_faux_mac_prefix

###########################################################

Expand Down Expand Up @@ -173,6 +179,9 @@ if [ -z "$remote" ]; then

cp topo/$mode/forch/* $container_inst/forch/
cp topo/$mode/faucet/* $container_inst/faucet/

find $container_inst/ -name *.yaml -exec sed -i "s/$DEFAULT_MAC_PREFIX/$FAUX_MAC_PREFIX/" {} \;

docker kill $container || true

if [ -n "$fot" ]; then
Expand Down
17 changes: 17 additions & 0 deletions bin/stack_functions
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ function add_oeth {
sudo ovs-vsctl add-port $br_a $iface_a -- set interface $iface_a ofport_request=$pt_a
}

function set_faux_mac_prefix {
export DEFAULT_MAC_PREFIX="9a:02:57:1e"
export DEFAULT_CLEAN_MAC_PREFIX="9a02571e"
if [ -z $FAUX_MAC_PREFIX ]; then
FAUX_MAC_PREFIX=$DEFAULT_MAC_PREFIX
fi

correct_mac_prefix=`echo $FAUX_MAC_PREFIX | egrep '([0-9a-zA-Z]{2}:){3}[0-9a-zA-Z]{2}'`
if [ -z $correct_mac_prefix ]; then
echo "$FAUX_MAC_PREFIX is an invalid mac prefix. FAUX_MAC_PREFIX should be in the format 'XX:XX:XX:XX'"
false
fi
CLEAN_MAC_PREFIX=`echo $FAUX_MAC_PREFIX | sed 's/://g'`
export FAUX_MAC_PREFIX=$FAUX_MAC_PREFIX
export CLEAN_MAC_PREFIX=$CLEAN_MAC_PREFIX
}

function add_faux {
switch=$1
port=$2
Expand Down
4 changes: 4 additions & 0 deletions controller/bin/controller_go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ else
ifconfig data0 up
fi

if [ -n "$CLEAN_MAC_PREFIX" ]; then
bin/rename_site_config $CLEAN_MAC_PREFIX
fi

echo Forch config
cat $FORCH_CONFIG

Expand Down
9 changes: 9 additions & 0 deletions controller/bin/rename_site_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

default_mac_prefix="9a02571e"

if [ "$1" != $default_mac_prefix ]; then
for f in `find /site/mac_addrs/ -name "$default_mac_prefix*"`; do
cp -r $f `echo $f | sed -e "s/$default_mac_prefix/$1/g"`
done
fi
8 changes: 5 additions & 3 deletions etc/start_faux
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ for option in $*; do
done

IFACE=faux-eth0
FAUX_MAC_PREFIX="${options['faux-mac-prefix']}"
PREFIX=$(($FAUX_NUM/256 + 1))
SUFFIX=$(($FAUX_NUM%256))
IPADDR=192.168.$PREFIX.$SUFFIX
GATEWAY=192.168.1.0

echo $FAUX_MAC_PREFIX
while ! ip link show $IFACE; do
sleep 2
done
Expand All @@ -42,7 +44,7 @@ else
ip route add default via $GATEWAY
fi

if [ -n "${option[ping]}" ]; then
if [ -n "${options[ping]}" ]; then
ping -c 10 $GATEWAY &
fi

Expand All @@ -52,8 +54,8 @@ ip route
if [ -n "${options[dnsmasq]}" ]; then
echo Configuring dnsmasq...
echo dhcp-range=192.168.1.10,192.168.1.255 >> /etc/dnsmasq.conf
echo dhcp-host=9a:02:57:1e:8f:01,192.168.1.1 >> /etc/dnsmasq.conf
echo dhcp-host=9a:02:57:1e:8f:02,192.168.1.2 >> /etc/dnsmasq.conf
echo dhcp-host=$FAUX_MAC_PREFIX:8f:01,192.168.1.1 >> /etc/dnsmasq.conf
echo dhcp-host=$FAUX_MAC_PREFIX:8f:02,192.168.1.2 >> /etc/dnsmasq.conf
dnsmasq --log-facility=/tmp/dnsmasq.log --log-dhcp
fi

Expand Down
8 changes: 4 additions & 4 deletions etc/test_fot.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Device 04 log count 0
275
100
274
9a02571e8f01: []
9a02571e8f02: []
9a02571e8f03: ['9a02571e8f03:hold:DaqException']
9a02571e8f05: ['9a02571e8f05:hold:DaqException']
9a99571e8f01: []
9a99571e8f02: []
9a99571e8f03: ['9a99571e8f03:hold:DaqException']
9a99571e8f05: ['9a99571e8f05:hold:DaqException']
5 packets transmitted, 5 received, 0% packet loss, XXX
5 packets transmitted, 0 received, XX errors, 100% packet loss, XXX
18 changes: 9 additions & 9 deletions testing/test_fot
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,30 @@ vlan=$($YQ '.dps."nz-kiwi-t2sw1".interfaces."1".native_vlan' $BEHAVIORAL_CONFIG)
echo $(( (vlan > 271) + (vlan > 276) )) | tee -a $TEST_RESULTS
echo $(( (vlan > 271) + (vlan > 276) )) | tee -a $TEST_RESULTS

monitor_daq_log "Send device result 9a:02:57:1e:8f:01 passed"
monitor_daq_log "Send device result 9a:02:57:1e:8f:02 failed"
monitor_daq_log "Target device 9a02571e8f03 test hold running"
monitor_daq_log "Target device 9a02571e8f05 test hold running"
monitor_daq_log "Send device result 9a:99:57:1e:8f:01 passed"
monitor_daq_log "Send device result 9a:99:57:1e:8f:02 failed"
monitor_daq_log "Target device 9a99571e8f03 test hold running"
monitor_daq_log "Target device 9a99571e8f05 test hold running"

echo `timestamp` stopping forch-faux-3
docker stop forch-faux-3 # Remove device 3 to generate port-down event.

log_count=$(fgrep "9a:02:57:1e:8f:04" $DAQ_BASE/cmdrun.log | wc -l)
log_count=$(fgrep "9a:99:57:1e:8f:04" $DAQ_BASE/cmdrun.log | wc -l)
echo Device 04 log count $log_count | tee -a $TEST_RESULTS

report_vlans

monitor_forch_log "Device 9a:02:57:1e:8f:04 is entering operational state from unauthenticated state"
monitor_forch_log "Device 9a:99:57:1e:8f:04 is entering operational state from unauthenticated state"

# Check if it's running in client/server or server/client mode and adjust expectations accordingly.
sserv_mode=$(fgrep ssserv $DAQ_BASE/cmdrun.log | wc -l)
if [[ $sserv_mode == 0 ]]; then
monitor_daq_log "Remaining target sets: \[9a02571e8f05\]"
monitor_daq_log "Remaining target sets: \[9a99571e8f05\]"
expected_timeouts=0
# Device 8f:05 doesn't timeout in this mode, so add artificial result for later on.
echo "9a02571e8f05: ['9a02571e8f05:hold:DaqException']" | sudo tee -a $DAQ_BASE/result.log
echo "9a99571e8f05: ['9a99571e8f05:hold:DaqException']" | sudo tee -a $DAQ_BASE/result.log
else
monitor_forch_log "Device 9a:02:57:1e:8f:03 disconnected"
monitor_forch_log "Device 9a:99:57:1e:8f:03 disconnected"
monitor_daq_log "Remaining target sets: \[\]"
expected_timeouts=2
fi
Expand Down
2 changes: 1 addition & 1 deletion topo/dva/forch/behaviors.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
device_mac_behaviors:
"9A:02:57:1E:8F:01":
"9a:02:57:1e:8f:01":
segment: INFRA
role: hello_world.foo.bar#bazqux@quuxquuz123
"02:03:04:00:00:03":
Expand Down

0 comments on commit 2ffdfc2

Please sign in to comment.