From fc8f9b4b1721a029a30bf41e6086cfbff085089d Mon Sep 17 00:00:00 2001 From: Phil Wise Date: Mon, 19 Mar 2018 16:31:31 +0100 Subject: Add a --secondary-network option to run-qemu-ota This sets up a simulated 'in vehicle' network. Add support for a Primary node with a DHCP server and a secondary node with a DHCP client. --- .../demo-network-config/files/25-dhcp-server.network | 12 ++++++++++++ .../demo-network-config/files/26-dhcp-client.network | 6 ++++++ .../demo-network-config/primary-network-config.bb | 16 ++++++++++++++++ .../demo-network-config/secondary-network-config.bb | 16 ++++++++++++++++ recipes-test/images/primary-image.bb | 12 ++++++++++++ recipes-test/images/secondary-image.bb | 5 ++++- scripts/qemucommand.py | 6 ++++++ scripts/run-qemu-ota | 3 +++ 8 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 recipes-test/demo-network-config/files/25-dhcp-server.network create mode 100644 recipes-test/demo-network-config/files/26-dhcp-client.network create mode 100644 recipes-test/demo-network-config/primary-network-config.bb create mode 100644 recipes-test/demo-network-config/secondary-network-config.bb create mode 100644 recipes-test/images/primary-image.bb diff --git a/recipes-test/demo-network-config/files/25-dhcp-server.network b/recipes-test/demo-network-config/files/25-dhcp-server.network new file mode 100644 index 0000000..4766f9a --- /dev/null +++ b/recipes-test/demo-network-config/files/25-dhcp-server.network @@ -0,0 +1,12 @@ +[Match] +Name=enp0s4 + +[Network] +Description=Private internal network between aktualizr Primary and Secondary nodes +DHCPServer=yes +Address=10.0.3.1/24 +IPForward=yes +IPMasquerade=yes + +[DHCPServer] +PoolOffset=10 \ No newline at end of file diff --git a/recipes-test/demo-network-config/files/26-dhcp-client.network b/recipes-test/demo-network-config/files/26-dhcp-client.network new file mode 100644 index 0000000..319664f --- /dev/null +++ b/recipes-test/demo-network-config/files/26-dhcp-client.network @@ -0,0 +1,6 @@ +[Match] +Name=enp0s4 + +[Network] +Description=Private internal network between aktualizr Primary and Secondary nodes +DHCP=yes diff --git a/recipes-test/demo-network-config/primary-network-config.bb b/recipes-test/demo-network-config/primary-network-config.bb new file mode 100644 index 0000000..78678a2 --- /dev/null +++ b/recipes-test/demo-network-config/primary-network-config.bb @@ -0,0 +1,16 @@ +DESCRIPTION = "Sample network configuration for an Uptane Primary" +LICENSE = "CLOSED" + +inherit allarch + +SRC_URI = "file://25-dhcp-server.network" + + +FILES_${PN} = "/usr/lib/systemd/network" + +PR = "1" + +do_install() { + install -d ${D}/usr/lib/systemd/network + install -m 0644 ${WORKDIR}/25-dhcp-server.network ${D}/usr/lib/systemd/network/ +} diff --git a/recipes-test/demo-network-config/secondary-network-config.bb b/recipes-test/demo-network-config/secondary-network-config.bb new file mode 100644 index 0000000..492d3ca --- /dev/null +++ b/recipes-test/demo-network-config/secondary-network-config.bb @@ -0,0 +1,16 @@ +DESCRIPTION = "Sample network configuration for an Uptane Secondary" +LICENSE = "CLOSED" + +inherit allarch + +SRC_URI = "file://26-dhcp-client.network" + + +FILES_${PN} = "/usr/lib/systemd/network" + +PR = "1" + +do_install() { + install -d ${D}/usr/lib/systemd/network + install -m 0644 ${WORKDIR}/26-dhcp-client.network ${D}/usr/lib/systemd/network/ +} diff --git a/recipes-test/images/primary-image.bb b/recipes-test/images/primary-image.bb new file mode 100644 index 0000000..6c06527 --- /dev/null +++ b/recipes-test/images/primary-image.bb @@ -0,0 +1,12 @@ +include recipes-core/images/core-image-minimal.bb + +SUMMARY = "A minimal Uptane Primary image running aktualizr, for testing with a Linux secondary" + +LICENSE = "MIT" + +IMAGE_INSTALL_remove = " \ + " + +IMAGE_INSTALL_append = " \ + primary-network-config \ + " diff --git a/recipes-test/images/secondary-image.bb b/recipes-test/images/secondary-image.bb index c7a91db..c1ce57a 100644 --- a/recipes-test/images/secondary-image.bb +++ b/recipes-test/images/secondary-image.bb @@ -15,4 +15,7 @@ IMAGE_INSTALL_remove = " \ aktualizr-implicit-prov \ " -IMAGE_INSTALL_append = " aktualizr-secondary " \ No newline at end of file +IMAGE_INSTALL_append = " \ + aktualizr-secondary \ + secondary-network-config \ + " diff --git a/scripts/qemucommand.py b/scripts/qemucommand.py index 6b1106d..e209a07 100644 --- a/scripts/qemucommand.py +++ b/scripts/qemucommand.py @@ -81,6 +81,7 @@ class QemuCommand(object): self.gdb = args.gdb self.pcap = args.pcap self.overlay = args.overlay + self.secondary_network = args.secondary_network def command_line(self): netuser = 'user,hostfwd=tcp:0.0.0.0:%d-:22,restrict=off' % self.ssh_port @@ -104,6 +105,11 @@ class QemuCommand(object): ] if self.pcap: cmdline += ['-net', 'dump,file=' + self.pcap] + if self.secondary_network: + cmdline += [ + '-net', 'nic,vlan=1,macaddr='+random_mac(), + '-net', 'socket,vlan=1,mcast=230.0.0.1:1234', + ] if self.gui: cmdline += ["-serial", "stdio"] else: diff --git a/scripts/run-qemu-ota b/scripts/run-qemu-ota index 56e4fbc..b2f55e9 100755 --- a/scripts/run-qemu-ota +++ b/scripts/run-qemu-ota @@ -33,6 +33,9 @@ def main(): help='Use an overlay storage image file. Will be created if it does not exist. ' + 'This option lets you have a persistent image without modifying the underlying image ' + 'file, permitting multiple different persistent machines.') + parser.add_argument('--secondary-network', action='store_true', dest='secondary_network', + help='Give the image a second network card connected to a virtual network. ' + + 'This can be used to test Uptane Primary/Secondary communication.') parser.add_argument('-n', '--dry-run', help='Print qemu command line rather then run it', action='store_true') args = parser.parse_args() try: -- cgit v1.2.3-54-g00ecf