Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import numpy
- # Feel free to add any imports you might need, and note that you might
- # not need to use either of the ones we've provided.
- from PS7_wsim import *
- class CSMACWNode(WirelessNode):
- def __init__(self,location,network,retry):
- WirelessNode.__init__(self,location,network,retry)
- self.cw = self.network.cwmin # Initialize to cwmin
- self.cwmin = self.network.cwmin
- self.cwmax = self.network.cwmax
- self.curr_decision = -1
- self.calculatedYet = False
- # Set any additional state or variables here if you need them.
- def channel_access(self, current_time, packet_size):
- # TODO: Your code here. Return true if the node should send a
- # packet in this timeslot (false otherwise). You can tell if
- # the channel is busy by using the self.network.channel_busy()
- # function.
- if self.calculatedYet == False:
- self.curr_decision = random.randint(1, self.cw) + current_time
- self.calculatedYet = True
- if (current_time == self.curr_decision) and not self.network.channel_busy():
- self.calculatedYet = False
- return True
- elif (current_time == self.curr_decision) and self.network.channel_busy():
- self.curr_decision = self.curr_decision + 1
- return False
- else:
- return False
- def on_collision(self, packet):
- self.cw = min(self.cw*2.0, self.cwmax)
- pass
- def on_success(self, packet):
- self.cw = max(self.cw*0.5, self.cwmin)
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement