Skip to content

Commit

Permalink
Merge dev into main (Sprint 9 hotfix) (#73)
Browse files Browse the repository at this point in the history
* Implement test orchestrator (#4)

* Initial work on test-orchestrator

* Ignore runtime folder

* Update runtime directory for test modules

* Fix logging
Add initial framework for running tests

* logging and misc cleanup

* logging changes

* Add a stop hook after all tests complete

* Refactor test_orc code

* Add arg passing
Add option to use locally cloned via install or remote via main project network orchestrator

* Fix baseline module
Fix orchestrator exiting only after timeout

* Add result file to baseline test module
Change result format to match closer to design doc

* Refactor pylint

* Skip test module if it failed to start

* Refactor

* Check for valid log level

---------

Co-authored-by: Jacob Boddey <[email protected]>

* Add issue report templates (#7)

* Add issue templates

* Update README.md

* Discover devices on the network (#5)

* Test run sync (#8)

* Initial work on test-orchestrator

* Ignore runtime folder

* Update runtime directory for test modules

* Fix logging
Add initial framework for running tests

* logging and misc cleanup

* logging changes

* Add a stop hook after all tests complete

* Refactor test_orc code

* Add arg passing
Add option to use locally cloned via install or remote via main project network orchestrator

* Fix baseline module
Fix orchestrator exiting only after timeout

* Add result file to baseline test module
Change result format to match closer to design doc

* Refactor pylint

* Skip test module if it failed to start

* Refactor

* Check for valid log level

* Add config file arg
Misc changes to network start procedure

* fix merge issues

* Update runner and test orch procedure
Add useful runtiem args

* Restructure test run startup process
Misc updates to work with net orch updates

* Refactor

---------

* Quick refactor (#9)

* Fix duplicate sleep calls

* Add net orc (#11)

* Add network orchestrator repository

* cleanup duplicate start and install scripts

* Temporary fix for python dependencies

* Remove duplicate python requirements

* remove duplicate conf files

* remove remote-net option

* cleanp unecessary files

* Add the DNS test module (#12)

* Add network orchestrator repository

* cleanup duplicate start and install scripts

* Temporary fix for python dependencies

* Remove duplicate python requirements

* remove duplicate conf files

* remove remote-net option

* cleanp unecessary files

* Add dns test module
Fix test module build process

* Add mac address of device under test to test container
Update dns test to use mac address filter

* Update dns module tests

* Change result output

* logging update

* Update test module for better reusability

* Load in module config to test module

* logging cleanup

* Update baseline module to new template
Misc cleanup

* Add ability to disable individual tests

* remove duplicate readme

* Update device directories

* Remove local folder

* Update device template
Update test module to work with new device config file format

* Change test module network config options
Do not start network services for modules not configured for network

* Refactor

---------

* Add baseline and pylint tests (#25)

* Discover devices on the network (#22)

* Discover devices on the network

* Add defaults when missing from config
Implement monitor wait period from config

* Add steady state monitor
Remove duplicate callback registrations

* Load devices into network orchestrator during testrun start

---------

Co-authored-by: jhughesbiot <[email protected]>

* Build dependencies first (#21)

* Build dependencies first

* Remove debug message

* Add depend on option to test modules

* Re-add single interface option

* Import subprocess

---------

Co-authored-by: jhughesbiot <[email protected]>

* Port scan test module (#23)

* Add network orchestrator repository

* cleanup duplicate start and install scripts

* Temporary fix for python dependencies

* Remove duplicate python requirements

* remove duplicate conf files

* remove remote-net option

* cleanp unecessary files

* Add dns test module
Fix test module build process

* Add mac address of device under test to test container
Update dns test to use mac address filter

* Update dns module tests

* Change result output

* logging update

* Update test module for better reusability

* Load in module config to test module

* logging cleanup

* Update baseline module to new template
Misc cleanup

* Add ability to disable individual tests

* remove duplicate readme

* Update device directories

* Remove local folder

* Update device template
Update test module to work with new device config file format

* Change test module network config options
Do not start network services for modules not configured for network

* Initial nmap test module add
Add device ip resolving to base module
Add network mounting for test modules

* Update ipv4 device resolving in test modules

* Map in ip subnets and remove hard coded references

* Add ftp port test

* Add ability to pass config for individual tests within a module
Update nmap module scan to run tests based on config

* Add full module check for compliance

* Add all tcp port scans to config

* Update nmap commands to match existing DAQ tests
Add udp scanning and tests

* logging cleanup

* Update TCP port scanning range
Update logging

* Merge device config into module config
Update device template

* fix merge issues

* Update timeouts
Add multi-threading for multiple scanns to run simultaneously
Add option to use scan scripts for services

* Fix merge issues

* Fix device configs

* Remove unecessary files

* Cleanup duplicate properties

* Cleanup install script

* Formatting (#26)

* Fix pylint issues in net orc

* more pylint fixes

* fix listener lint issues

* fix logger lint issues

* fix validator lint issues

* fix util lint issues

* Update base network module linting issues

* Cleanup linter issues for dhcp modules
Remove old code testing code

* change to single quote delimeter

* Cleanup linter issues for ntp module

* Cleanup linter issues for radius module

* Cleanup linter issues for template module

* fix linter issues with faux-dev

* Test results (#27)

* Collect all module test results

* Fix test modules without config options

* Add timestamp to test results

* Test results (#28)

* Collect all module test results

* Fix test modules without config options

* Add timestamp to test results

* Add attempt timing and device info to test results

* Ignore disabled test containers when generating results

* Fully skip modules that are disabled

* Fix pylint test and skip internet tests so CI passes (#29)

* disable internet checks for pass

* fix pylint test

* Increase pylint score (#31)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

---------

Co-authored-by: jhughesbiot <[email protected]>

* Pylint (#32)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

---------

Co-authored-by: Jacob Boddey <[email protected]>

* Add license header (#36)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

* Add ovs control into network orchestrator

* Add verification methods for the base network

* Add network validation and misc logging updates

* remove ovs module

* add license header to all python files

---------

Co-authored-by: Jacob Boddey <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* Ovs (#35)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

* Add ovs control into network orchestrator

* Add verification methods for the base network

* Add network validation and misc logging updates

* remove ovs module

---------

Co-authored-by: Jacob Boddey <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* remove ovs files added back in during merge

* Nmap (#38)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

* Add ovs control into network orchestrator

* Add verification methods for the base network

* Add network validation and misc logging updates

* remove ovs module

* add license header to all python files

* Update tcp scans to speed up full port range scan
Add version checking
Implement ssh version checking

* Add unknown port checks
Match unknown ports to existing services
Add unknown ports without existing services to results file

---------

Co-authored-by: Jacob Boddey <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* Create startup capture (#37)

* Connection (#40)

* Initial add of connection test module with ping test

* Update host user resolving

* Update host user resolving for validator

* add get user method to validator

* Conn mac oui (#42)

* Initial add of connection test module with ping test

* Update host user resolving

* Update host user resolving for validator

* add get user method to validator

* Add mac_oui test
Add option to return test result and details of test for reporting

* Con mac address (#43)

* Initial add of connection test module with ping test

* Update host user resolving

* Update host user resolving for validator

* add get user method to validator

* Add mac_oui test
Add option to return test result and details of test for reporting

* Add connection.mac_address test

* Dns (#44)

* Add MDNS test

* Update existing mdns logging to be more consistent with other tests

* Add startup and monitor captures

* File permissions (#45)

* Fix validator file permissions

* Fix test module permissions

* Fix device capture file permissions

* Fix device results permissions

* Add connection single ip test (#47)

* Nmap results (#49)

* Update processing of nmap results to use xml output and json conversions for stability

* Update matching with regex to prevent wrong service matches and duplicate processing for partial matches

* Update max port scan range

* Framework restructure (#50)

* Restructure framework and modules

* Fix CI paths

* Fix base module

* Add build script

* Remove build logs

* Update base and template docker files to fit the new format
Implement a template option on network modules
Fix skipping of base image build

* remove base image build in ci

* Remove group from chown

---------

Co-authored-by: jhughesbiot <[email protected]>

* Ip control (#51)

* Add initial work for ip control module

* Implement ip control module with additional cleanup methods

* Update link check to not use error stream

* Add error checking around container network configurations

* Add network cleanup for namespaces and links

* formatting

* Move config to /local (#52)

* Move config to /local

* Fix testing config

* Fix ovs_control config location

* Fix faux dev config location

* Add documentation (#53)

* Sync dev to main (#56)

* Merge dev into main (Sprint 7 and 8) (#33)

* Implement test orchestrator (#4)

* Initial work on test-orchestrator

* Ignore runtime folder

* Update runtime directory for test modules

* Fix logging
Add initial framework for running tests

* logging and misc cleanup

* logging changes

* Add a stop hook after all tests complete

* Refactor test_orc code

* Add arg passing
Add option to use locally cloned via install or remote via main project network orchestrator

* Fix baseline module
Fix orchestrator exiting only after timeout

* Add result file to baseline test module
Change result format to match closer to design doc

* Refactor pylint

* Skip test module if it failed to start

* Refactor

* Check for valid log level

---------

Co-authored-by: Jacob Boddey <[email protected]>

* Add issue report templates (#7)

* Add issue templates

* Update README.md

* Discover devices on the network (#5)

* Test run sync (#8)

* Initial work on test-orchestrator

* Ignore runtime folder

* Update runtime directory for test modules

* Fix logging
Add initial framework for running tests

* logging and misc cleanup

* logging changes

* Add a stop hook after all tests complete

* Refactor test_orc code

* Add arg passing
Add option to use locally cloned via install or remote via main project network orchestrator

* Fix baseline module
Fix orchestrator exiting only after timeout

* Add result file to baseline test module
Change result format to match closer to design doc

* Refactor pylint

* Skip test module if it failed to start

* Refactor

* Check for valid log level

* Add config file arg
Misc changes to network start procedure

* fix merge issues

* Update runner and test orch procedure
Add useful runtiem args

* Restructure test run startup process
Misc updates to work with net orch updates

* Refactor

---------

* Quick refactor (#9)

* Fix duplicate sleep calls

* Add net orc (#11)

* Add network orchestrator repository

* cleanup duplicate start and install scripts

* Temporary fix for python dependencies

* Remove duplicate python requirements

* remove duplicate conf files

* remove remote-net option

* cleanp unecessary files

* Add the DNS test module (#12)

* Add network orchestrator repository

* cleanup duplicate start and install scripts

* Temporary fix for python dependencies

* Remove duplicate python requirements

* remove duplicate conf files

* remove remote-net option

* cleanp unecessary files

* Add dns test module
Fix test module build process

* Add mac address of device under test to test container
Update dns test to use mac address filter

* Update dns module tests

* Change result output

* logging update

* Update test module for better reusability

* Load in module config to test module

* logging cleanup

* Update baseline module to new template
Misc cleanup

* Add ability to disable individual tests

* remove duplicate readme

* Update device directories

* Remove local folder

* Update device template
Update test module to work with new device config file format

* Change test module network config options
Do not start network services for modules not configured for network

* Refactor

---------

* Add baseline and pylint tests (#25)

* Discover devices on the network (#22)

* Discover devices on the network

* Add defaults when missing from config
Implement monitor wait period from config

* Add steady state monitor
Remove duplicate callback registrations

* Load devices into network orchestrator during testrun start

---------

Co-authored-by: jhughesbiot <[email protected]>

* Build dependencies first (#21)

* Build dependencies first

* Remove debug message

* Add depend on option to test modules

* Re-add single interface option

* Import subprocess

---------

Co-authored-by: jhughesbiot <[email protected]>

* Port scan test module (#23)

* Add network orchestrator repository

* cleanup duplicate start and install scripts

* Temporary fix for python dependencies

* Remove duplicate python requirements

* remove duplicate conf files

* remove remote-net option

* cleanp unecessary files

* Add dns test module
Fix test module build process

* Add mac address of device under test to test container
Update dns test to use mac address filter

* Update dns module tests

* Change result output

* logging update

* Update test module for better reusability

* Load in module config to test module

* logging cleanup

* Update baseline module to new template
Misc cleanup

* Add ability to disable individual tests

* remove duplicate readme

* Update device directories

* Remove local folder

* Update device template
Update test module to work with new device config file format

* Change test module network config options
Do not start network services for modules not configured for network

* Initial nmap test module add
Add device ip resolving to base module
Add network mounting for test modules

* Update ipv4 device resolving in test modules

* Map in ip subnets and remove hard coded references

* Add ftp port test

* Add ability to pass config for individual tests within a module
Update nmap module scan to run tests based on config

* Add full module check for compliance

* Add all tcp port scans to config

* Update nmap commands to match existing DAQ tests
Add udp scanning and tests

* logging cleanup

* Update TCP port scanning range
Update logging

* Merge device config into module config
Update device template

* fix merge issues

* Update timeouts
Add multi-threading for multiple scanns to run simultaneously
Add option to use scan scripts for services

* Fix merge issues

* Fix device configs

* Remove unecessary files

* Cleanup duplicate properties

* Cleanup install script

* Formatting (#26)

* Fix pylint issues in net orc

* more pylint fixes

* fix listener lint issues

* fix logger lint issues

* fix validator lint issues

* fix util lint issues

* Update base network module linting issues

* Cleanup linter issues for dhcp modules
Remove old code testing code

* change to single quote delimeter

* Cleanup linter issues for ntp module

* Cleanup linter issues for radius module

* Cleanup linter issues for template module

* fix linter issues with faux-dev

* Test results (#27)

* Collect all module test results

* Fix test modules without config options

* Add timestamp to test results

* Test results (#28)

* Collect all module test results

* Fix test modules without config options

* Add timestamp to test results

* Add attempt timing and device info to test results

* Ignore disabled test containers when generating results

* Fully skip modules that are disabled

* Fix pylint test and skip internet tests so CI passes (#29)

* disable internet checks for pass

* fix pylint test

* Increase pylint score (#31)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

---------

Co-authored-by: jhughesbiot <[email protected]>

* Pylint (#32)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

---------

Co-authored-by: Jacob Boddey <[email protected]>

* Add license header (#36)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

* Add ovs control into network orchestrator

* Add verification methods for the base network

* Add network validation and misc logging updates

* remove ovs module

* add license header to all python files

---------

Co-authored-by: Jacob Boddey <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* Ovs (#35)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

* Add ovs control into network orchestrator

* Add verification methods for the base network

* Add network validation and misc logging updates

* remove ovs module

---------

Co-authored-by: Jacob Boddey <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* remove ovs files added back in during merge

* Nmap (#38)

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Misc pylint fixes
Fix test module logger

* remove unused files

* more formatting

* revert breaking pylint changes

* more formatting

* fix results file

* More formatting

* ovs module formatting

* Add ovs control into network orchestrator

* Add verification methods for the base network

* Add network validation and misc logging updates

* remove ovs module

* add license header to all python files

* Update tcp scans to speed up full port range scan
Add version checking
Implement ssh version checking

* Add unknown port checks
Match unknown ports to existing services
Add unknown ports without existing services to results file

---------

Co-authored-by: Jacob Boddey <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* Create startup capture (#37)

* Connection (#40)

* Initial add of connection test module with ping test

* Update host user resolving

* Update host user resolving for validator

* add get user method to validator

* Conn mac oui (#42)

* Initial add of connection test module with ping test

* Update host user resolving

* Update host user resolving for validator

* add get user method to validator

* Add mac_oui test
Add option to return test result and details of test for reporting

* Con mac address (#43)

* Initial add of connection test module with ping test

* Update host user resolving

* Update host user resolving for validator

* add get user method to validator

* Add mac_oui test
Add option to return test result and details of test for reporting

* Add connection.mac_address test

* Dns (#44)

* Add MDNS test

* Update existing mdns logging to be more consistent with other tests

* Add startup and monitor captures

* File permissions (#45)

* Fix validator file permissions

* Fix test module permissions

* Fix device capture file permissions

* Fix device results permissions

* Add connection single ip test (#47)

* Nmap results (#49)

* Update processing of nmap results to use xml output and json conversions for stability

* Update matching with regex to prevent wrong service matches and duplicate processing for partial matches

* Update max port scan range

* Framework restructure (#50)

* Restructure framework and modules

* Fix CI paths

* Fix base module

* Add build script

* Remove build logs

* Update base and template docker files to fit the new format
Implement a template option on network modules
Fix skipping of base image build

* remove base image build in ci

* Remove group from chown

---------

Co-authored-by: jhughesbiot <[email protected]>

* Ip control (#51)

* Add initial work for ip control module

* Implement ip control module with additional cleanup methods

* Update link check to not use error stream

* Add error checking around container network configurations

* Add network cleanup for namespaces and links

* formatting

* Move config to /local (#52)

* Move config to /local

* Fix testing config

* Fix ovs_control config location

* Fix faux dev config location

* Add documentation (#53)

---------

Co-authored-by: jhughesbiot <[email protected]>
Co-authored-by: jhughesbiot <[email protected]>
Co-authored-by: Noureddine <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* Sprint 8 Hotfix (#54)

* Fix connection results.json

* Re add try/catch

* Fix log level

* Debug test module load order

* Add depends on to nmap module

* Remove logging change

---------

Co-authored-by: jhughesbiot <[email protected]>
Co-authored-by: jhughesbiot <[email protected]>
Co-authored-by: Noureddine <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>

* Fix missing results on udp tests when tcp ports are also defined (#59)

* Add licence header (#61)

* Resolve merge conflict

* Add network docs (#63)

* Add network docs

* Rename to readme

* Add link to template module

* Dhcp (#64)

* Add initial work for ip control module

* Implement ip control module with additional cleanup methods

* Update link check to not use error stream

* Add error checking around container network configurations

* Add network cleanup for namespaces and links

* formatting

* initial work on adding grpc functions for dhcp tests

* rework code to allow for better usage and unit testing

* working poc for test containers and grpc client to dhcp-1

* Move grpc client code into base image

* Move grpc proto builds outside of dockerfile into module startup script

* Setup pythonpath var in test module base startup process
misc cleanup

* pylinting and logging updates

* Add python path resolving to network modules
Update grpc path to prevent conflicts
misc pylinting

* Change lease resolving method to fix pylint issue

* cleanup unit tests

* cleanup unit tests

* Add grpc updates to dhcp2 module
Update dhcp_config to deal with missing optional variables

* Add grpc updates to dhcp2 module
Update dhcp_config to deal with missing optional variables

* fix line endings

* misc cleanup

* Dhcp (#67)

* Add initial work for ip control module

* Implement ip control module with additional cleanup methods

* Update link check to not use error stream

* Add error checking around container network configurations

* Add network cleanup for namespaces and links

* formatting

* initial work on adding grpc functions for dhcp tests

* rework code to allow for better usage and unit testing

* working poc for test containers and grpc client to dhcp-1

* Move grpc client code into base image

* Move grpc proto builds outside of dockerfile into module startup script

* Setup pythonpath var in test module base startup process
misc cleanup

* pylinting and logging updates

* Add python path resolving to network modules
Update grpc path to prevent conflicts
misc pylinting

* Change lease resolving method to fix pylint issue

* cleanup unit tests

* cleanup unit tests

* Add grpc updates to dhcp2 module
Update dhcp_config to deal with missing optional variables

* Add grpc updates to dhcp2 module
Update dhcp_config to deal with missing optional variables

* fix line endings

* misc cleanup

* Move isc-dhcp-server and radvd to services
Move DHCP server monitoring and booting to python script

* Add grpc methods to interact with dhcp_server module
Update dhcp_server to control radvd server directly from calls
Fix radvd service status method

* Add updates to dhcp2 module
Update radvd service

* Add license headers

* Add connection.dhcp_address test (#68)

* Add NTP tests (#60)

* Add ntp support test

* Add extra log message

* Modify descriptions

* Pylint

* Pylint (#69)

---------

Co-authored-by: jhughesbiot <[email protected]>

* Add ipv6 tests (#65)

* Add ipv6 tests

* Check for ND_NS

* Connection private address (#71)

* Add ntp support test

* Add extra log message

* Modify descriptions

* Pylint

* formatting

* Change isc-dhcp service setup
Fix dhcpd logging
Add start and stop methods to grpc dhcp client
Add dhcp2 client
Inttial private_addr test

* Add max lease time
Add unit tests

* fix last commit

* finish initial work on test

* pylinting

* Breakup test and allow better failure reporting

* restore network after test

* Wait for device to get a lease from original dhcp range after network restore

* pylinting

* Fix ipv6 tests

---------

Co-authored-by: Jacob Boddey <[email protected]>

* fix windows line ending

* Fix python import

* move isc-dhcp service commands to their own class
update logging
pylinting

* fix dhcp1

* Initial CI testing for tests (#72)

* Fix radvd conf

---------

Co-authored-by: jhughesbiot <[email protected]>
Co-authored-by: jhughesbiot <[email protected]>
Co-authored-by: Noureddine <[email protected]>
Co-authored-by: SuperJonotron <[email protected]>
  • Loading branch information
5 people authored Jul 14, 2023
1 parent 103c5a5 commit 6e0e22e
Show file tree
Hide file tree
Showing 39 changed files with 1,572 additions and 267 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- cron: '0 13 * * *'

jobs:
testrun:
testrun_baseline:
name: Baseline
runs-on: ubuntu-20.04
timeout-minutes: 20
Expand All @@ -17,11 +17,21 @@ jobs:
- name: Run tests
shell: bash {0}
run: testing/test_baseline


testrun_tests:
name: Tests
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- name: Checkout source
uses: actions/[email protected]
- name: Run tests
shell: bash {0}
run: testing/test_tests
pylint:
name: Pylint
runs-on: ubuntu-20.04
timeout-minutes: 20
runs-on: ubuntu-22.04
timeout-minutes: 5
steps:
- name: Checkout source
uses: actions/[email protected]
Expand Down
56 changes: 56 additions & 0 deletions modules/network/dhcp-1/bin/isc-dhcp-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

CONFIG_FILE=/etc/dhcp/dhcpd.conf
DHCP_PID_FILE=/var/run/dhcpd.pid
DHCP_LOG_FILE=/runtime/network/dhcp1-dhcpd.log

stop_dhcp(){
# Directly kill by PID file reference
if [ -f "$DHCP_PID_FILE" ]; then
kill -9 $(cat $DHCP_PID_FILE) || true
rm -f $DHCP_PID_FILE
fi
}

start_dhcp(){
/usr/sbin/dhcpd -d &> $DHCP_LOG_FILE &
}

case "$1" in
start)
start_dhcp
;;
stop)
stop_dhcp
;;
restart)
stop_dhcp
sleep 1
start_dhcp
;;
status)
if [ -f "$DHCP_PID_FILE" ]; then
echo "isc-dhcp service is running."
else
echo "isc-dhcp service is not running."
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
3 changes: 2 additions & 1 deletion modules/network/dhcp-1/bin/start_network_service
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ cp /testrun/conf/isc-dhcp-server /etc/default/
cp /testrun/conf/dhcpd.conf /etc/dhcp/dhcpd.conf
cp /testrun/conf/radvd.conf /etc/radvd.conf

# Move the radvd-sevice file to the correct location
# Move the service files to the correct location
cp /testrun/bin/isc-dhcp-service /usr/local/bin/
cp /testrun/bin/radvd-service /usr/local/bin/

# Start the DHCP Server
Expand Down
55 changes: 28 additions & 27 deletions modules/network/dhcp-1/conf/dhcpd.conf
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
default-lease-time 300;

failover peer "failover-peer" {
primary;
address 10.10.10.2;
port 847;
peer address 10.10.10.3;
peer port 647;
max-response-delay 60;
max-unacked-updates 10;
mclt 3600;
split 128;
load balance max seconds 3;
}

subnet 10.10.10.0 netmask 255.255.255.0 {
option ntp-servers 10.10.10.5;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
option domain-name-servers 10.10.10.4;
interface veth0;
authoritative;
pool {
failover peer "failover-peer";
range 10.10.10.10 10.10.10.20;
}
default-lease-time 30;
max-lease-time 30;

failover peer "failover-peer" {
primary;
address 10.10.10.2;
port 847;
peer address 10.10.10.3;
peer port 647;
max-response-delay 60;
max-unacked-updates 10;
mclt 30;
split 128;
load balance max seconds 3;
}

subnet 10.10.10.0 netmask 255.255.255.0 {
option ntp-servers 10.10.10.5;
option subnet-mask 255.255.255.0;
option broadcast-address 10.10.10.255;
option routers 10.10.10.1;
option domain-name-servers 10.10.10.4;
interface veth0;
authoritative;
pool {
failover peer "failover-peer";
range 10.10.10.10 10.10.10.20;
}
}
8 changes: 4 additions & 4 deletions modules/network/dhcp-1/conf/isc-dhcp-server
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="veth0"
#INTERFACESv6="veth0"
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
# Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACESv4="veth0"
#INTERFACESv6="veth0"
50 changes: 25 additions & 25 deletions modules/network/dhcp-1/conf/module_config.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"config": {
"meta": {
"name": "dhcp-1",
"display_name": "DHCP Primary",
"description": "Primary DHCP server with IPv6 SLAAC"
},
"network": {
"interface": "veth0",
"enable_wan": false,
"ip_index": 2
},
"grpc":{
"port": 5001
},
"docker": {
"depends_on": "base",
"mounts": [
{
"source": "runtime/network",
"target": "/runtime/network"
}
]
}
}
{
"config": {
"meta": {
"name": "dhcp-1",
"display_name": "DHCP Primary",
"description": "Primary DHCP server with IPv6 SLAAC"
},
"network": {
"interface": "veth0",
"enable_wan": false,
"ip_index": 2
},
"grpc":{
"port": 5001
},
"docker": {
"depends_on": "base",
"mounts": [
{
"source": "runtime/network",
"target": "/runtime/network"
}
]
}
}
}
5 changes: 2 additions & 3 deletions modules/network/dhcp-1/conf/radvd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ interface veth0
prefix fd10:77be:4186::/64 {
AdvOnLink on;
AdvAutonomous on;
AdvRouterAddr on;
AdvSourceLLAddress off;
AdvRouterAddr on;
};
};
};
67 changes: 57 additions & 10 deletions modules/network/dhcp-1/python/src/grpc_server/dhcp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
LOGGER = None
CONFIG_FILE = '/etc/dhcp/dhcpd.conf'
DEFAULT_LEASE_TIME_KEY = 'default-lease-time'
MAX_LEASE_TIME_KEY = 'max-lease-time'


class DHCPConfig:
"""Represents the DHCP Servers configuration and gives access to modify it"""

def __init__(self):
self._default_lease_time = 300
self._default_lease_time = 30
self._max_lease_time = 30
self._subnets = []
self._peer = None
self._reserved_hosts = []
Expand Down Expand Up @@ -120,17 +122,50 @@ def set_range(self, start, end, subnet=0, pool=0):
octets[-1] = '0'
dhcp_subnet = '.'.join(octets)

#Update the subnet and range
self._subnets[subnet].set_subnet(dhcp_subnet)
# Calcualte the netmask from the range
prefix = self.calculate_prefix_length(start, end)
netmask = self.calculate_netmask(prefix)

#Update the subnet, range and netmask
self._subnets[subnet].set_subnet(dhcp_subnet, netmask)
self._subnets[subnet].pools[pool].set_range(start, end)

def calculate_prefix_length(self, start_ip, end_ip):
start_octets = start_ip.split('.')
end_octets = end_ip.split('.')

start_int = int(
''.join(format(int(octet), '08b') for octet in start_octets), 2)
end_int = int(''.join(format(int(octet), '08b') for octet in end_octets), 2)

xor_result = start_int ^ end_int
prefix_length = 32 - xor_result.bit_length()

return prefix_length

def calculate_netmask(self, prefix_length):
num_network_bits = prefix_length
num_host_bits = 32 - num_network_bits

netmask_int = (2**num_network_bits - 1) << num_host_bits
netmask_octets = [(netmask_int >> (i * 8)) & 0xff for i in range(3, -1, -1)]

return '.'.join(str(octet) for octet in netmask_octets)

def __str__(self):

config = ('{DEFAULT_LEASE_TIME_KEY} {DEFAULT_LEASE_TIME};'
if self._default_lease_time is not None else '')
config += ('\n\r{MAX_LEASE_TIME_KEY} {MAX_LEASE_TIME};'
if self._max_lease_time is not None else '')

# Encode the top level config options
config = """{DEFAULT_LEASE_TIME_KEY} {DEFAULT_LEASE_TIME};"""
#config = """{DEFAULT_LEASE_TIME_KEY} {DEFAULT_LEASE_TIME};"""
config = config.format(length='multi-line',
DEFAULT_LEASE_TIME_KEY=DEFAULT_LEASE_TIME_KEY,
DEFAULT_LEASE_TIME=self._default_lease_time)
DEFAULT_LEASE_TIME=self._default_lease_time,
MAX_LEASE_TIME_KEY=MAX_LEASE_TIME_KEY,
MAX_LEASE_TIME=self._max_lease_time)

# Encode the failover peer
config += '\n\n' + str(self._peer)
Expand Down Expand Up @@ -358,12 +393,24 @@ def set_subnet(self, subnet, netmask=None):
self._subnet = subnet
self._subnet_mask = netmask

# Calculate the broadcast from the subnet
octets = subnet.split('.')
octets[-1] = '255'
dhcp_broadcast = '.'.join(octets)
# Calculate the broadcast from the subnet and netmask
broadcast = self.calculate_broadcast_address(subnet, netmask)
self._broadcast = broadcast

def calculate_broadcast_address(self, subnet_address, netmask):
subnet_octets = subnet_address.split('.')
netmask_octets = netmask.split('.')

subnet_int = int(
''.join(format(int(octet), '08b') for octet in subnet_octets), 2)
netmask_int = int(
''.join(format(int(octet), '08b') for octet in netmask_octets), 2)

broadcast_int = subnet_int | (~netmask_int & 0xffffffff)
broadcast_octets = [(broadcast_int >> (i * 8)) & 0xff
for i in range(3, -1, -1)]

self._broadcast = dhcp_broadcast
return '.'.join(str(octet) for octet in broadcast_octets)

def resolve_subnet(self, subnet):
subnet_parts = subnet.split('\n')
Expand Down
11 changes: 11 additions & 0 deletions modules/network/dhcp-1/python/src/grpc_server/dhcp_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CONFIG_FILE = 'conf/dhcpd.conf'
DHCP_CONFIG = None


def get_config_file_path():
current_dir = os.path.dirname(os.path.abspath(__file__))
module_dir = os.path.dirname(
Expand Down Expand Up @@ -91,6 +92,15 @@ def test_resolve_config_with_hosts(self):
self.assertIsNotNone(host)
print('ResolveConfigWithHosts:\n' + str(config_with_hosts))

def test_set_subnet_range(self):
range_start = '10.0.0.100'
range_end = '10.0.0.200'
DHCP_CONFIG.set_range(range_start, range_end)
subnets = DHCP_CONFIG.resolve_subnets(str(DHCP_CONFIG))
pool = subnets[0].pools[0]
self.assertTrue(pool.range_start == range_start
and pool.range_end == range_end)
print('SetSubnetRange:\n' + str(DHCP_CONFIG))

if __name__ == '__main__':
suite = unittest.TestSuite()
Expand All @@ -100,6 +110,7 @@ def test_resolve_config_with_hosts(self):
suite.addTest(DHCPConfigTest('test_add_reserved_host'))
suite.addTest(DHCPConfigTest('test_delete_reserved_host'))
suite.addTest(DHCPConfigTest('test_resolve_config_with_hosts'))
suite.addTest(DHCPConfigTest('test_set_subnet_range'))

runner = unittest.TextTestRunner()
runner.run(suite)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _make_lease(self, lease):
self.hw_addr = sections[0]
self.ip = sections[1]
self.hostname = sections[2]
self.expires = sections[3] + '' '' + sections[4]
self.expires = sections[3] + ' ' + sections[4]
self.manufacturer = ' '.join(sections[5:])

def get_millis(self, timestamp):
Expand Down
6 changes: 3 additions & 3 deletions modules/network/dhcp-1/python/src/grpc_server/dhcp_leases.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def get_leases(self):
leases = []
lease_list_raw = self._get_lease_list()
LOGGER.info('Raw Leases:\n' + str(lease_list_raw) + '\n')
lease_list_start = lease_list_raw.find('=========',0)
lease_list_start = lease_list_raw.find('\n',lease_list_start)
lease_list = lease_list_raw[lease_list_start+1:]
lease_list_start = lease_list_raw.find('=========', 0)
lease_list_start = lease_list_raw.find('\n', lease_list_start)
lease_list = lease_list_raw[lease_list_start + 1:]
lines = lease_list.split('\n')
for line in lines:
try:
Expand Down
Loading

0 comments on commit 6e0e22e

Please sign in to comment.