#2041: Implement NTP protocol for server

This commit is contained in:
Nick Todd
2023-11-14 15:13:05 +00:00
parent 764d9561bd
commit f320487128
2 changed files with 44 additions and 10 deletions

View File

@@ -2,22 +2,22 @@ from __future__ import annotations
from ipaddress import IPv4Address
from typing import Optional
from pydantic import BaseModel
from primaite.simulator.network.protocols.packet import DataPacket
from datetime import datetime
class NTPRequest(BaseModel):
"""Represents a NTP Request packet."""
pass
ntp_client: IPv4Address = None
class NTPReply(BaseModel):
"""Represents a NTP Reply packet."""
pass
ntp_datetime: datetime
"NTP datetime object set by NTP Server."
class NTPPacket(DataPacket):
@@ -31,4 +31,12 @@ class NTPPacket(DataPacket):
ntp_request: NTPRequest
"NTP Request packet sent by NTP Client."
ntp_reply: Optional[NTPReply] = None
"NTP Reply packet generated by NTP Server."
def generate_reply(self, time: datetime) -> NTPPacket:
""" Generate a NTPPacket containing the time in a NTPReply object
:param time: datetime object representing the time from the NTP server.
:return: A new NTPPacket object.
"""
self.ntp_reply = NTPReply(time)
return self