2041: Make NTP work with TCP transport layer

This commit is contained in:
Nick Todd
2023-12-06 16:42:28 +00:00
parent 12ede2329b
commit 50a6e17fab
4 changed files with 12 additions and 7 deletions

View File

@@ -601,7 +601,7 @@ class ActionManager:
max_nics_per_node: int = 8, # allows calculating shape
max_acl_rules: int = 10, # allows calculating shape
protocols: List[str] = ["TCP", "UDP", "ICMP"], # allow mapping index to protocol
ports: List[str] = ["HTTP", "DNS", "ARP", "FTP"], # allow mapping index to port
ports: List[str] = ["HTTP", "DNS", "ARP", "FTP", "NTP"], # allow mapping index to port
ip_address_list: Optional[List[str]] = None, # to allow us to map an index to an ip address.
act_map: Optional[Dict[int, Dict]] = None, # allows restricting set of possible actions
) -> None:

View File

@@ -25,6 +25,8 @@ from primaite.simulator.system.services.dns.dns_client import DNSClient
from primaite.simulator.system.services.dns.dns_server import DNSServer
from primaite.simulator.system.services.ftp.ftp_client import FTPClient
from primaite.simulator.system.services.ftp.ftp_server import FTPServer
from primaite.simulator.system.services.ntp.ntp_client import NTPClient
from primaite.simulator.system.services.ntp.ntp_server import NTPServer
from primaite.simulator.system.services.red_services.data_manipulation_bot import DataManipulationBot
from primaite.simulator.system.services.web_server.web_server import WebServer
@@ -257,6 +259,8 @@ class PrimaiteGame:
"WebServer": WebServer,
"FTPClient": FTPClient,
"FTPServer": FTPServer,
"NTPClient": NTPClient,
"NTPServer": NTPServer,
}
if service_type in service_types_mapping:
_LOGGER.debug(f"installing {service_type} on node {new_node.hostname}")

View File

@@ -23,7 +23,7 @@ class NTPClient(Service):
def __init__(self, **kwargs):
kwargs["name"] = "NTPClient"
kwargs["port"] = Port.NTP
kwargs["protocol"] = IPProtocol.UDP
kwargs["protocol"] = IPProtocol.TCP
super().__init__(**kwargs)
self.start()
@@ -65,7 +65,7 @@ class NTPClient(Service):
self,
payload: NTPPacket,
session_id: Optional[str] = None,
dest_ip_address: IPv4Address = ntp_server,
dest_ip_address: IPv4Address = None,
dest_port: [Port] = Port.NTP,
**kwargs,
) -> bool:
@@ -79,8 +79,6 @@ class NTPClient(Service):
:return: True if successful, False otherwise.
"""
self.ip_addr = payload.ntp_request.ntp_client
self.sys_log.info(f"{self.name}: Sending NTP request {payload.ntp_request.ntp_client}")
return super().send(
payload=payload,
dest_ip_address=dest_ip_address,
@@ -101,6 +99,8 @@ class NTPClient(Service):
:param session_id: The Session ID the payload is to originate from. Optional.
:return: True if successful, False otherwise.
"""
self.sys_log.info(f"{self.name}: Receiving NTP request from {payload.ntp_request.ntp_client}")
if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client):
_LOGGER.debug(f"{payload} is not a NTPPacket")
return False
@@ -116,7 +116,7 @@ class NTPClient(Service):
"""Send request to ntp_server."""
ntp_request = NTPRequest(ntp_client=self.ip_addr)
ntp_server_packet = NTPPacket(ntp_request=ntp_request)
self.send(payload=ntp_server_packet)
self.send(payload=ntp_server_packet, dest_ip_address=self.ntp_server)
def apply_timestep(self, timestep: int) -> None:
"""

View File

@@ -16,7 +16,7 @@ class NTPServer(Service):
def __init__(self, **kwargs):
kwargs["name"] = "NTPServer"
kwargs["port"] = Port.NTP
kwargs["protocol"] = IPProtocol.UDP
kwargs["protocol"] = IPProtocol.TCP
super().__init__(**kwargs)
self.start()
@@ -60,6 +60,7 @@ class NTPServer(Service):
:return: True if valid NTP request else False.
"""
self.sys_log.info(f"{self.name} received request from {payload.ntp_request.ntp_client}")
if not (isinstance(payload, NTPPacket) and payload.ntp_request.ntp_client):
_LOGGER.debug(f"{payload} is not a NTPPacket")
return False