def __init__(self): frequencyBand = FrequencyBand([FsplAttenuation]) super(CounterTrafficEnv, self).__init__(frequencyBand, deviceCount=2) # The difference between the lastly received values from both devices # summed up with the COUNTER_BOUND will be the observation. self.observation_space = spaces.Discrete( 2 * CounterTrafficEnv.COUNTER_BOUND) SimMan.init() self.senders: List[self.SenderDevice] = [ CounterTrafficEnv.SenderDevice("Sender 1", 0, 2, self.frequencyBand, 1), CounterTrafficEnv.SenderDevice("Sender 2", 0, -2, self.frequencyBand, 3) ] self.deviceIndexToMacDict: Dict[int, bytes] = { i: s.macAddr for i, s in enumerate(self.senders) } self.senders[0].destinationMac = self.senders[1].macAddr self.senders[1].destinationMac = self.senders[0].macAddr interpreter = self.CounterTrafficInterpreter(self) self.rrm = SimpleRrmDevice("RRM", 0, 0, self.frequencyBand, self.deviceIndexToMacDict, interpreter)
def device_grid(request): """ A parametrized device fixture that sets up SendingDevices in a grid arrangement with 1 m distance between adjacent devices. Tests using this fixture will be run with every specified parameter. """ n = request.param # Number of devices to be created SimMan.init() frequencyBand = FrequencyBand([FsplAttenuation]) devices = [] cols = int(sqrt(n)) for i in range(n): initialDelay = random.uniform(0, SEND_INTERVAL) devices.append( SendingDevice(i, i / cols, i % cols, frequencyBand, SEND_INTERVAL, initialDelay)) return devices
def simple_phy(): # initialize SimPy environment SimMan.init() # create a wireless frequency band with FSPL attenuation frequencyBand = FrequencyBand([FsplAttenuation]) # create two network devices device1 = Device("1", 0, 0) device2 = Device("2", 1, 1) # create the SimplePhy network stack layers device1Phy = SimplePhy("Phy", device1, frequencyBand) device2Phy = SimplePhy("Phy", device2, frequencyBand) setup = dotdict() setup.frequencyBand = frequencyBand setup.device1 = device1 setup.device2 = device2 setup.device1Phy = device1Phy setup.device2Phy = device2Phy return setup
def test_gate_listener_generator(caplog): caplog.set_level(logging.DEBUG, logger='gymwipe.networking.construction') SimMan.init() # Checking side effects by using two identical modules again modules = MyModule("Test1"), MyModule("Test2") def main(): for i in range(3): for module in modules: module.gates["bIn"].send("msg" + str(i)) yield SimMan.timeout(1) SimMan.process(main()) SimMan.runSimulation(40) for module in modules: # Non-queued PortListener should only have received the first message, # since receiving takes 10 time units and the send interval is 1 time unit. assert module.logs[2] == ["msg0"] # Queued PortListener should have received all messages. assert module.logs[3] == ["msg" + str(n) for n in range(3)]
def simman(): SimMan.init() yield SimMan