Skip to content

Commit

Permalink
openvswitch - fix multiple issues, ref #885
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Ehlers committed May 14, 2024
1 parent 1e210bf commit 867d9df
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 83 deletions.
2 changes: 1 addition & 1 deletion appliances/openvswitch-management.gns3a
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"docker": {
"adapters": 16,
"image": "gns3/openvswitch:latest",
"environment": "MANAGEMENT_INTERFACE=1"
"environment": "MANAGEMENT_INTERFACE=eth0"
}
}
10 changes: 4 additions & 6 deletions docker/openvswitch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apk add --no-cache openvswitch nano bash bash-completion
RUN sed -i s,/bin/ash,/bin/bash, /etc/passwd

# Enable bash completion
RUN echo -e "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc
RUN echo -e "source /etc/bash/bash_completion.sh" >> ~/.bashrc

# Enable openvswitch bash completion
RUN echo -e "source /usr/share/bash-completion/completions/ovs-vsctl-bashcomp.bash" >> ~/.bashrc
Expand All @@ -15,10 +15,8 @@ RUN echo -e "source /usr/share/bash-completion/completions/ovs-appctl-bashcomp.b
# Configure the prompt
RUN echo -e "PS1='\h:\w\$ '" >> ~/.bashrc

RUN mkdir /var/run/openvswitch
VOLUME [ "/root", "/etc/openvswitch" ]

VOLUME /etc/openvswitch/
ADD init.sh /etc/openvswitch/

ADD boot.sh /bin/boot.sh

CMD /bin/bash /bin/boot.sh
CMD /etc/openvswitch/init.sh; bash
18 changes: 18 additions & 0 deletions docker/openvswitch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Docker Open vSwitch for GNS3

This creates a container for using Open vSwitch in GNS3.

This container supports ethernet interfaces and comes
with bridges from br0 to br3.

By default, all interfaces are connected to br0.

If you set the `MANAGEMENT_INTERFACE` environment variable to
an interface name, that interface will not be connected to br0.


## Building the container

```
docker build -t gns3/openvswitch .
```
19 changes: 0 additions & 19 deletions docker/openvswitch/README.rst

This file was deleted.

57 changes: 0 additions & 57 deletions docker/openvswitch/boot.sh

This file was deleted.

52 changes: 52 additions & 0 deletions docker/openvswitch/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
#
# Copyright (C) 2024 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

firstrun=0
[ -f "/etc/openvswitch/conf.db" ] || firstrun=1

if [ $firstrun -ne 0 ]; then
# create database
ovsdb-tool create /etc/openvswitch/conf.db /usr/share/openvswitch/vswitch.ovsschema
fi

# start openvswitch daemons
mkdir -p /var/log/openvswitch /var/run/openvswitch
ovsdb-server --detach --pidfile --remote=punix:/var/run/openvswitch/db.sock \
--log-file --verbose=off:syslog
ovs-vswitchd --detach --pidfile --log-file --verbose=off:syslog

if [ $firstrun -ne 0 ]; then
ovs-vsctl --no-wait init

# create br0..br3
for intf in br0 br1 br2 br3; do
ovs-vsctl add-br $intf
ovs-vsctl set bridge $intf datapath_type=netdev
done

# add all ethernet interfaces to br0, except MANAGEMENT_INTERFACE
[ "$MANAGEMENT_INTERFACE" = 1 ] && MANAGEMENT_INTERFACE=eth0
sed -n 's/^ *\(eth[0-9]*\): .*/\1/p' /proc/net/dev | sort -V | \
while read -r intf; do
[ "$intf" = "$MANAGEMENT_INTERFACE" ] || ovs-vsctl add-port br0 "$intf"
done
fi

# activate br0..br3
for intf in br0 br1 br2 br3; do
ip link set dev $intf up
done

0 comments on commit 867d9df

Please sign in to comment.