Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fe10e73
Implement test orchestrator (#4)
jhughesoti Apr 25, 2023
6f3a7fe
Add issue report templates (#7)
jboddey Apr 26, 2023
e05c383
Discover devices on the network (#5)
jboddey Apr 26, 2023
823709e
Test run sync (#8)
jhughesoti Apr 28, 2023
ba6afc4
Quick refactor (#9)
jboddey Apr 28, 2023
c87a976
Fix duplicate sleep calls
jhughesoti Apr 28, 2023
34ce211
Add net orc (#11)
jhughesoti May 2, 2023
ceba453
Add the DNS test module (#12)
jhughesoti May 4, 2023
0837a9c
Add baseline and pylint tests (#25)
noursaidi May 16, 2023
4171e5f
Discover devices on the network (#22)
jboddey May 16, 2023
be829a3
Build dependencies first (#21)
jboddey May 16, 2023
84d9ff9
Port scan test module (#23)
jhughesoti May 17, 2023
07432ee
Fix device configs
jboddey May 17, 2023
7b27e23
Remove unecessary files
jhughesoti May 17, 2023
5ac8726
Cleanup duplicate properties
jhughesoti May 17, 2023
2c4efe8
Cleanup install script
jhughesoti May 17, 2023
25fd8a5
Formatting (#26)
jhughesoti May 22, 2023
41aaaf7
Test results (#27)
jhughesoti May 23, 2023
ea60b41
Test results (#28)
jhughesoti May 25, 2023
b6a6cdc
Fix pylint test and skip internet tests so CI passes (#29)
noursaidi May 25, 2023
3d53ecb
Increase pylint score (#31)
jboddey May 25, 2023
b91fff5
Pylint (#32)
jhughesoti May 30, 2023
b84a026
Add license header (#36)
jhughesoti May 30, 2023
622b12d
merge main
jhughesoti May 31, 2023
38d71aa
Ovs (#35)
jhughesoti May 31, 2023
00be9cb
remove ovs files added back in during merge
jhughesoti May 31, 2023
f331239
Nmap (#38)
jhughesoti Jun 5, 2023
2a68fba
Create startup capture (#37)
jboddey Jun 5, 2023
8e8e154
Connection (#40)
jhughesoti Jun 7, 2023
6ff220b
Conn mac oui (#42)
jhughesoti Jun 8, 2023
4ca8f44
Con mac address (#43)
jhughesoti Jun 8, 2023
ff04f43
Dns (#44)
jhughesoti Jun 8, 2023
752f701
File permissions (#45)
jhughesoti Jun 9, 2023
f6e4e93
Add connection single ip test (#47)
jhughesoti Jun 12, 2023
bca0db8
Nmap results (#49)
jhughesoti Jun 15, 2023
5b56a79
Framework restructure (#50)
jboddey Jun 15, 2023
7bb9366
Ip control (#51)
jhughesoti Jun 20, 2023
b0d14c2
Move config to /local (#52)
jboddey Jun 23, 2023
94e937f
Add documentation (#53)
jboddey Jun 23, 2023
098de20
Sync dev to main (#56)
jboddey Jun 28, 2023
f185bb1
Fix missing results on udp tests when tcp ports are also defined (#59)
jhughesoti Jun 29, 2023
355c838
Add licence header (#61)
jboddey Jul 3, 2023
d374640
Resolve merge conflicts
jboddey Jul 3, 2023
8d65386
Resolve merge conflict
jboddey Jul 3, 2023
26f8c5b
Add network docs (#63)
jboddey Jul 4, 2023
4a5c1ea
Dhcp (#64)
jhughesoti Jul 5, 2023
af8367c
Dhcp (#67)
jhughesoti Jul 6, 2023
7dd5772
Add connection.dhcp_address test (#68)
jhughesoti Jul 6, 2023
9ef0d4f
Add NTP tests (#60)
jboddey Jul 12, 2023
2ae337d
Add ipv6 tests (#65)
jboddey Jul 12, 2023
59ab65f
Merge branch 'main' into dev
jboddey Jul 12, 2023
fe4bf43
Connection private address (#71)
jhughesoti Jul 13, 2023
0c550c8
fix windows line ending
jhughesoti Jul 13, 2023
2df6b4a
Fix python import
jboddey Jul 13, 2023
bfae1e0
move isc-dhcp service commands to their own class
jhughesoti Jul 13, 2023
4bdacf3
fix dhcp1
jhughesoti Jul 13, 2023
a57393b
Merge branch 'main' into dev
jboddey Jul 14, 2023
d376655
Initial CI testing for tests (#72)
noursaidi Jul 14, 2023
01761dd
Fix radvd conf
jboddey Jul 14, 2023
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
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/checkout@v2.3.4
- 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/checkout@v2.3.4
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