diff --git a/esds/simulator.py b/esds/simulator.py index 74f126e..fc76daf 100644 --- a/esds/simulator.py +++ b/esds/simulator.py @@ -306,14 +306,11 @@ class Simulator: """ nsrc=self.nodes[src] if self.netmat[interface]["is_wired"]: - if self.nodes[dst]["turned_on"]: - self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=src) - self.update_sharing(dst,1,interface) # Update sharing first - # Note that in the following we send more data than expected to handle bandwidth sharing (datasize*8*sharing): - duration=datasize*8/(self.netmat[interface]["bandwidth"][src,dst]/self.sharing[interface][dst])+self.netmat[interface]["latency"][src,dst] - self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time,True)) - else: - nsrc["state"]="call_blocking" # Try later when node is on + self.log("Send "+str(datasize)+" bytes to n"+str(dst)+" on "+interface,node=src) + self.update_sharing(dst,1,interface) # Update sharing first + # Note that in the following we send more data than expected to handle bandwidth sharing (datasize*8*sharing): + duration=datasize*8/(self.netmat[interface]["bandwidth"][src,dst]/self.sharing[interface][dst])+self.netmat[interface]["latency"][src,dst] + self.add_event(0,duration+self.time,(src,dst,interface,data,datasize,duration,datasize,self.time,self.nodes[dst]["turned_on"])) else: self.log("Send "+str(datasize)+" bytes on "+interface,node=src) for dst in self.list_receivers(nsrc,interface): @@ -400,7 +397,6 @@ class Simulator: if perform_delivery: dst["interfaces"][interface].put((data,start_at,self.time)) dst["interfaces_queue_size"][interface]+=1 - self.update_sharing(dst.node_id,-1,interface) self.log("Receive "+str(datasize)+" bytes on "+interface,node=int(dst_id)) # If node is receiving makes it consume (this way if there is a timeout, it will be removed!) if dst["state"] == "call_blocking" and dst["request"] == "receive": @@ -408,6 +404,7 @@ class Simulator: dst["state"]="running" dst.rqueue.put(("receive",0)) self.sync_node_non_blocking(dst,timeout_remove_only=True) + self.update_sharing(dst.node_id,-1,interface) src["state"]="running" src.rqueue.put(("send",0)) self.sync_node_non_blocking(src,timeout_remove_only=True) diff --git a/tests/api_send_eth0_1s1r/out b/tests/api_send_eth0_1s1r/out index 7b8f88d..9168e55 100644 --- a/tests/api_send_eth0_1s1r/out +++ b/tests/api_send_eth0_1s1r/out @@ -8,5 +8,8 @@ [t=3.000,src=n1] Turned off [t=4.000,src=n1] Turned on [t=5.000,src=n1] Receive failed code=-1 -[t=18.000,src=n0] End -[t=18.000,src=esds] Simulation ends +[t=5.000,src=n1] Turned off +[t=18.000,src=n0] End transmission +[t=18.000,src=n0] Send 15 bytes to n1 on eth0 +[t=33.000,src=n0] End transmission +[t=33.000,src=esds] Simulation ends diff --git a/tests/api_send_eth0_1s1r/receiver.py b/tests/api_send_eth0_1s1r/receiver.py index 514cbbe..d2a3656 100644 --- a/tests/api_send_eth0_1s1r/receiver.py +++ b/tests/api_send_eth0_1s1r/receiver.py @@ -17,5 +17,6 @@ def execute(api): code, data=api.receivet("eth0",1) msg="Received: "+data if code == 0 else "Receive failed code="+str(code) api.log(msg) + api.turn_off() diff --git a/tests/api_send_eth0_1s1r/sender.py b/tests/api_send_eth0_1s1r/sender.py index 64293da..8abb5e7 100644 --- a/tests/api_send_eth0_1s1r/sender.py +++ b/tests/api_send_eth0_1s1r/sender.py @@ -5,4 +5,6 @@ def execute(api): api.send("eth0","Hello World!",1,1) api.wait(1) # Goto t=3s api.send("eth0","Hello World!",15,1) # Communication should not be aborted even if receiver turned_off (e.g UDP) - api.log("End") # Should be printed at t=18s \ No newline at end of file + api.log("End transmission") # Should be printed at t=18s + api.send("eth0","Hello World!",15,1) # Now receiver is off + api.log("End transmission") # Should be printed at t=33s \ No newline at end of file