From f96410b58e9d7c0e13c1213b560108c2ac5364f2 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 28 Sep 2019 10:54:54 -0600 Subject: [PATCH] tools/simbridge.sh: Add simbridge.sh to simplify the simulator bridge creation. --- boards/sim/sim/sim/NETWORK-LINUX.txt | 16 +++++---- tools/README.txt | 9 +++++ tools/simbridge.sh | 49 ++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 6 deletions(-) create mode 100755 tools/simbridge.sh diff --git a/boards/sim/sim/sim/NETWORK-LINUX.txt b/boards/sim/sim/sim/NETWORK-LINUX.txt index 796d9882bc..c11f767272 100644 --- a/boards/sim/sim/sim/NETWORK-LINUX.txt +++ b/boards/sim/sim/sim/NETWORK-LINUX.txt @@ -43,10 +43,10 @@ pre-existing bridge device, or the initialization will fail. The simulation will NOT create the bridge for you. To create the bridge, first install the bridge utilities package for your -platform (the bridge-utils RPM in RedHat, for example). Then execute a +platform (the net-tools RPM in RedHat, for example). Then execute a command like the following: - # brctl addbr nuttx0 + # ip link add nuttx0 type bridge This will create the nuttx0 bridge. Once created, the bridge may be used by one or more simulations. You only need one bridge per host; if you start @@ -63,7 +63,7 @@ that the subnet chosen should not already be in use. For example, if you want to use the 172.26.23.0/24 subnet for your simluations, you would do something like the following: - # brctl addbr nuttx0 + # ip link add nuttx0 type bridge # ifconfig nuttx0 172.26.23.1/24 The standard Linux ifconfig utility will automatically add the appropriate @@ -83,7 +83,7 @@ with NuttX. For example, if you have a secondary eth1 interface on your host, you can simply connect it to the network you want your simulations to access, and run the following command: - # brctl addif nuttx0 eth1 + # ip link set eth1 master nuttx0 From that point on, your simulations will be directly connected to the same network as your eth1 interface. Note that your bridge will generally not need @@ -93,8 +93,8 @@ If you only have a single interface, you can configure your system so that eth0 (or other primary interface) is on the bridge. To do this, you would execute commands like the following from the system console: - # brctl addbr nuttx0 - # brctl addif nuttx0 eth0 + # ip link add nuttx0 type bridge + # ip link set eth0 master nuttx0 # ifconfig nuttx0 # route add -net default gw ... @@ -131,6 +131,10 @@ NOTES I don't know if VMware's consumer products have similar issues or not. + o tools/simbridge.sh could make the bridge setup easier: + + # tools/simbridge.sh eth0 on + # tools/simbridge.sh eth0 off -- Steve http://floating.io diff --git a/tools/README.txt b/tools/README.txt index 0565bf362a..fc58914d32 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -895,6 +895,15 @@ sethost.sh -h will show this help test and terminate selects configuration file. Default: .config +simbridge.sh +------------ + + Helper script used to set up a bridge to support networking with the + simulator under Linux. General usage: + + $ tools/simbridge.sh + Usage: tools/simbridge.sh + showsize.sh ----------- diff --git a/tools/simbridge.sh b/tools/simbridge.sh new file mode 100755 index 0000000000..2e6a2d8d33 --- /dev/null +++ b/tools/simbridge.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# tools/simbridge.sh +# +# Copyright (C) 2019 Xiaomi. All rights reserved. +# Author: Xiang Xiao +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +if [ $# != 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ "$2" == "on" ]; then + ip link add nuttx0 type bridge + ip addr flush dev $1 + ip link set $1 master nuttx0 + ip link set dev nuttx0 up + dhclient nuttx0 +else + ip link delete nuttx0 + dhclient $1 +fi