Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom faux mac prefix #329

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions bin/run_controller
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ if [[ -z $vxlan ]]; then
docker exec $CONTAINER ip link set data0 up
fi

if [ $CLEAN_MAC_PREFIX != "$DEFAULT_CLEAN_MAC_PREFIX" ]; then
docker exec $CONTAINER /root/bin/rename_site_config $CLEAN_MAC_PREFIX
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should go inside controller_go -- basically just pass the CLEAN_MAC_PREFIX in (as per the docker_envs use above), and then inside of the controller sort out what to do about it. Generally better to avoid the "docker exec" solution because it's a lot harder to debug/diagnose/trace -- the only reason it's done for the data0 interface is because it has to be done externally after the container is created (effective race condition).

fi

echo Container $CONTAINER started as $cid

while [ ! -e $INSTDIR/$FAUCET_SOCK ]; do
Expand Down
11 changes: 7 additions & 4 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if FAUX_MAC_PREFIX is not defined? Doesn't this need a default somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_faux_mac_prefix defines the default

cd $ROOT

# If the first argument is a number, then it's a port designation.
Expand All @@ -22,7 +25,7 @@ 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

Expand All @@ -42,14 +45,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
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
5 changes: 5 additions & 0 deletions controller/bin/rename_site_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

for f in `find /site/mac_addrs/ -name '9a02571*'`; do
cp -r $f `echo $f | sed -e "s/9a02571e/$1/g"`
done
5 changes: 3 additions & 2 deletions etc/start_faux
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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
Expand Down Expand Up @@ -52,8 +53,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
grafnu marked this conversation as resolved.
Show resolved Hide resolved
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