Unverified Commit 8a8d6a9c authored by Jakob Görgen's avatar Jakob Görgen
Browse files

split up channel and socket ceration in independent funciton calls

parent 149387fc
......@@ -125,40 +125,43 @@ class Simulator(abc.ABC):
raise Exception("interface does not need a channel as it is not connected")
return interface.channel
def _get_socket_and_chan(
def _get_socket(
self, inst: inst_base.Instantiation, interface: sys_conf.Interface
) -> tuple[sys_conf.Channel, inst_base.Socket] | tuple[None, None]:
) -> inst_base.Socket | None:
# get the channel associated with this interface
chan = self._get_sys_chan(interface=interface)
# check if interfaces channel is simulator internal, i.e. doesnt need an instanciation
if not self._chan_needs_instance(chan):
return None, None
# create channel simualtion object
channel = self.experiment.retrieve_or_create_channel(chan)
return None
# create the socket to listen on or connect to
socket = inst.get_socket(interface=interface)
return (channel, socket)
return socket
def _get_channels_and_sockets(
self, inst: inst_base.Instantiation
) -> tuple[list[sim_chan.Channel], list[inst_base.Socket]]:
channels = []
def _get_sockets(self, inst: inst_base.Instantiation) -> list[inst_base.Socket]:
sockets = []
for comp_spec in self._components:
for interface in comp_spec.interfaces():
channel, socket = self._get_socket_and_chan(
inst=inst, interface=interface
)
if channel is None or socket is None:
socket = self._get_socket_and_chan(inst=inst, interface=interface)
if socket is None:
continue
channels.append(channel)
sockets.append(socket)
return channels, sockets
return sockets
def _get_channel(self, chan: sys_conf.Channel) -> sim_chan.Channel | None:
if self._chan_needs_instance(chan):
return self.experiment.retrieve_or_create_channel(chan=chan)
return None
def _get_channels(self, inst: inst_base.Instantiation) -> list[sim_chan.Channel]:
channels = []
for comp_spec in self._components:
for chan in self.experiment.retrieve_or_create_channel(chan=chan):
channel = self._get_channel(chan=chan)
if channel is None:
continue
channels.append(channel)
return channels
# pylint: disable=unused-argument
@abc.abstractmethod
......
......@@ -86,8 +86,7 @@ class WireNet(NetSim):
eth_latency = None
sync_period = None
run_sync = False
channels, sockets = self._get_channels_and_sockets(inst=inst)
assert len(sockets) == 2
channels = self._get_channels(inst=inst)
for channel in channels:
sync_period = min(sync_period, channel.sync_period)
run_sync = run_sync or channel._synchronized
......@@ -101,6 +100,9 @@ class WireNet(NetSim):
assert sync_period is not None
assert eth_latency is not None
sockets = self._get_sockets(inst=inst)
assert len(sockets) == 2
cmd = inst.join_repo_base(self._relative_executable_path)
cmd += f"{sockets[0]} {sockets[1]} {run_sync} {sync_period} {eth_latency}"
......@@ -138,7 +140,7 @@ class SwitchNet(NetSim):
eth_latency = None
sync_period = None
run_sync = False
channels, sockets = self._get_channels_and_sockets(inst=inst)
channels = self._get_channels(inst=inst)
for channel in channels:
sync_period = min(sync_period, channel.sync_period)
run_sync = run_sync or channel._synchronized
......@@ -164,6 +166,7 @@ class SwitchNet(NetSim):
)
cmd += " " + pcap_file
sockets = self._get_sockets(inst=inst)
listen, connect = base.Simulator.split_sockets_by_type(sockets)
for sock in connect:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment