def main(): parser = OptionParser(option_class=eng_option, conflict_handler="resolve") parser.add_option("", "--PHYport", type="intx", default=8013, help="PHY communication socket port, [default=%default]") parser.add_option("", "--MACport", type="intx", default=8001, help="MAC communication socket port, [default=%default]") parser.add_option( "-i", "--interp", type="intx", default=10, help="USRP2 interpolation factor value, [default=%default]\ 5 -> 802.11a/g, OFDM T_Symbol=4us, \ 10 -> 802.11p, OFDM T_Symbol=8us") parser.add_option("", "--regime", type="string", default="5", help="OFDM regimecode [default=%default]\ 1 -> 6 (3) Mbit/s (BPSK r=0.5), \ 2 -> 9 (4.5) Mbit/s (BPSK r=0.75), \ 3 -> 12 (6) Mbit/s (QPSK r=0.5), \ 4 -> 18 (9) Mbit/s (QPSK r=0.75), \ 5 -> 24 (12) Mbit/s (QAM16 r=0.5), \ 6 -> 36 (18) Mbit/s (QAM16 r=0.75), \ 7 -> 48 (24) Mbit/s (QAM64 r=0.66), \ 8 -> 54 (27) Mbit/s (QAM64 r=0.75)") parser.add_option("-n", "--node", type="intx", default=1, help="Number of USRP2 node, [default=%default]") parser.add_option("", "--beta", type="float", default=150000, help="Scaling Time Parameter, [default=%default]") parser.add_option("-t", "--time_slot", type="float", default=9e-6, help="Time slot value, [default=%default]") parser.add_option( "-B", "--BI", type="float", default=1, help="Beacon Interval (BI) value in seconds, [default=%default]") parser.add_option( "-S", "--SIFS", type="float", default=16e-6, help="Short Inter-frame space (SIFS) value, [default=%default]") parser.add_option('', "--retx", action="store_true", default=False, help="Retransmissions enabled, [default=%default]") parser.add_option('', "--RTS", action="store_true", default=False, help="RTS-threshold enabled, [default=%default]") parser.add_option('-v', "--V", action="store_true", default=True, help="Print debug information, [default=%default]") (options, args) = parser.parse_args() my_mac = MAC.usrp2_node(options.node) # MAC address for this node dest_mac = MAC.usrp2_node( 2) # Dummy value (updated when an incoming packet arrives) beta = options.beta # scaling time parameter tslot = options.time_slot * beta SIFS = options.SIFS * beta DIFS = SIFS + 2 * tslot Preamble = DIFS #16e-6 PLCP_header = 4e-6 * beta ACK_time = Preamble + PLCP_header CW_min = 15 CW_max = 1023 RTS_THRESHOLD = 150 dot11FragmentationTh = 1036 # TX time estimation for a CTS and an ACK packet empty_values = {"duration": 0, "mac_ra": my_mac, "timestamp": time.time()} CTS_empty = MAC.generate_pkt("CTS", options.interp, options.regime, empty_values) T_cts = CTS_empty["INFO"]["txtime"] ACK_empty = MAC.generate_pkt("ACK", options.interp, options.regime, empty_values) T_ack = ACK_empty["INFO"]["txtime"] # Set socket ports PHY_port = options.PHYport #PHYRX_port = options.PHYRXport MAC_port = options.MACport # Variables involving MAC tests testing = False # Testing mode active, used to conduct trials N_TESTS = 1000 # Number of tests N_TESTS_INI = N_TESTS LONG_TESTS = 20 # Payload length for tests payload_test = "0000" + LONG_TESTS * '1' # Payload for tests test_with_sensing = True # Carrier Sensing (CS) allowed during the test total_processing_time = 0 # Total processing time t_sense_mean = 0 # CS average time t_csense = 0 # CS time t_MAC = 0 # MAC time t_MAC_mean = 0 # MAC average time packet_i = 0 # Packets sent counter n_sensing = 0 # Number of CS performed # 'State' controls the state of the MAC State = "IDLE" # Initial Conditions of the Finite State Machine NAV = 0 # Network Allocation Vector N_RETRIES = 0 # Retries to send a packet counter busy_in_wfd = False # Busy in Wait_for_DIFS state BO_frozen = "NO" # Backoff frozen TX_attempts = 0 # Tries to send a packet counter CTS_failed = False # CTS reception failed chan = "FREE" # Channel state = IDDLE N_SEQ = 0 # Sequence number counter N_FRAG = 0 # Fragment number counter first_tx = True # Is the first attempt to send a packet? frag_count = 0 # Counter used during fragmentation data_temp_reass = "" # Initial variable to perform de re-assembly process verbose = True # Shows when the MAC is in 'IDDLE' state beaconing = False # Is ON the Beaconing process? fragmenting = 0 # Is the packet received a fragment? if options.V: print "=============================================" print " \t MAC layer: DCF + RTS/CTS" print "=============================================" print "MAC address:", MAC.which_dir(my_mac) print "Rate = ", options.regime print "tslot(s): %f \t SIFS(s): %f" % (tslot, SIFS) print "DIFS(s): %f \t T_ACK(s): %f" % (DIFS, ACK_time) print "pseudo-random exp. BACKOFF [%i,%i]" % (CW_min, CW_max) if options.RTS: print "RTS/CTS: enabled" print "\t with RTS Threshold(Bytes): %i \t" % RTS_THRESHOLD else: print "RTS/CTS: disabled" print "Fragmentation Threshold (Bytes):", dot11FragmentationTh if options.retx: print "Retransmissions: enabled" else: print "Retransmissions: disabled" print "Scaling time parameter = ", beta print "============================================="
def RX_Client(options, my_mac, phy_rx_server): print "RX_client is waiting for the wireless medium!!!!!!!!!!!!!" phy_rx_client, phy_rx_addr = phy_rx_server.accept() while 1: #phy_rx_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #phy_rx_client.connect((socket.gethostname(), options.PHYRXport)) # PHY 802.11 frame arrival from the wireless medium pkt = phy_rx_client.recv(10000) arrived_packet = mac.parse_mac(pkt) print "PHY 802.11 frame arrival from the wireless medium!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" if (arrived_packet["HEADER"] == "DATA" or arrived_packet["HEADER"] == "DATA_FRAG"): if arrived_packet["DATA"]["INFO"][ "mac_add1"] == my_mac: # Is the data packet addressed to this node? data.push(arrived_packet["DATA"]) else: other.push("random data") if (arrived_packet["HEADER"] == "ACK"): if arrived_packet["DATA"]["INFO"][ "RX_add"] == my_mac: # Is the ACK addressed to this node? ack.push(arrived_packet["DATA"]) if (arrived_packet["HEADER"] == "RTS"): #It is a RTS rts.push(arrived_packet["DATA"]) if (arrived_packet["HEADER"] == "CTS"): #It is a CTS cts.push(arrived_packet["DATA"]) if (arrived_packet["HEADER"] == "BEACON"): #It is a BEACON beacon = arrived_packet["DATA"] beacon = beacon["INFO"] msg = plcp.new_beacon() msg["MAC"] = beacon["mac_add2"] msg["timestamp"] = beacon["timestamp"] msg["BI"] = beacon["BI"] msg["OFFSET"] = time.time() - beacon["timestamp"] x = bcn.length() updated = False # Update the beacon list for i in range(0, x): if msg["MAC"] == bcn.read(i)["MAC"]: bcn.remove(i) bcn.insert(i, msg) updated = True if updated == False: bcn.insert(x + 1, msg) if (arrived_packet["HEADER"] == ""): print "No packet arrived" #DEBUG print "=========== BUFFER STATUS ===========" print "DATA [%i]" % data.length() print "ACK [%i]" % ack.length() print "RTS [%i]" % rts.length() print "CTS [%i]" % cts.length() print "OTHER [%i]" % other.length() print "=====================================" print "\n\n" # Beacon list print "========= NEIGHBOR NODES INFORMATION ==========" for i in range(0, bcn.length()): item = bcn.read(i) print "[MAC = %s]\t [Timestamp = %s]\t [Beacon Interval = %s]\t [OFFSET = %s]" % ( mac.which_dir(item["MAC"]), item["timestamp"], item["BI"], item["OFFSET"]) print "===============================================" phy_rx_client.close()
def main(): parser = OptionParser(option_class=eng_option, conflict_handler="resolve") parser.add_option("", "--PHYport", type="intx", default=8013, help="PHY communication socket port, [default=%default]") parser.add_option("", "--MACport", type="intx", default=8001, help="MAC communication socket port, [default=%default]") parser.add_option("-i", "--interp", type="intx", default=10, help="USRP2 interpolation factor value, [default=%default]\ 5 -> 802.11a/g, OFDM T_Symbol=4us, \ 10 -> 802.11p, OFDM T_Symbol=8us") parser.add_option("", "--regime", type="string", default="1", help="OFDM regimecode [default=%default]\ 1 -> 6 (3) Mbit/s (BPSK r=0.5), \ 2 -> 9 (4.5) Mbit/s (BPSK r=0.75), \ 3 -> 12 (6) Mbit/s (QPSK r=0.5), \ 4 -> 18 (9) Mbit/s (QPSK r=0.75), \ 5 -> 24 (12) Mbit/s (QAM16 r=0.5), \ 6 -> 36 (18) Mbit/s (QAM16 r=0.75), \ 7 -> 48 (24) Mbit/s (QAM64 r=0.66), \ 8 -> 54 (27) Mbit/s (QAM64 r=0.75)") parser.add_option("-n", "--node", type="intx", default=1, help="Number of USRP2 node, [default=%default]") parser.add_option("", "--beta", type="float", default=50000, help="Scaling Time Parameter, [default=%default]") parser.add_option("-t", "--time_slot", type="float", default=9e-6, help="Time slot value, [default=%default]") parser.add_option("-B", "--BI", type="float", default=1, help="Beacon Interval (BI) value in seconds, [default=%default]") parser.add_option("-S", "--SIFS", type="float", default=16e-6, help="Short Inter-frame space (SIFS) value, [default=%default]") parser.add_option('', "--retx", action="store_true", default=False, help="Retransmissions enabled, [default=%default]") parser.add_option('', "--RTS", action="store_true", default=True, help="RTS-threshold enabled, [default=%default]") parser.add_option('-v', "--V", action="store_true", default=False, help="Print debug information, [default=%default]") (options, args) = parser.parse_args () my_mac = MAC.usrp2_node(options.node) # MAC address for this node dest_mac = MAC.usrp2_node(2) # Dummy value (updated when an incoming packet arrives) """ IEEE 802.11-a MAC parameters """ beta = options.beta # scaling time parameter tslot = options.time_slot * beta SIFS = options.SIFS * beta DIFS = SIFS + 2 * tslot Preamble = DIFS #16e-6 PLCP_header = 4e-6 * beta ACK_time = Preamble + PLCP_header CW_min = 15 CW_max = 1023 RTS_THRESHOLD = 150 dot11FragmentationTh = 1036 # TX time estimation for a CTS and an ACK packet empty_values = {"duration":0, "mac_ra":my_mac, "timestamp":time.time()} CTS_empty = MAC.generate_pkt("CTS", options.interp, options.regime, empty_values) T_cts = CTS_empty["INFO"]["txtime"] ACK_empty = MAC.generate_pkt("ACK", options.interp, options.regime, empty_values) T_ack = ACK_empty["INFO"]["txtime"] # Set socket ports PHY_port = options.PHYport #PHYRX_port = options.PHYRXport MAC_port = options.MACport # Variables involving MAC tests testing = False # Testing mode active, used to conduct trials N_TESTS = 1000 # Number of tests N_TESTS_INI = N_TESTS LONG_TESTS = 20 # Payload length for tests payload_test = "0000" + LONG_TESTS*'1' # Payload for tests test_with_sensing = True # Carrier Sensing (CS) allowed during the test total_processing_time = 0 # Total processing time t_sense_mean = 0 # CS average time t_csense = 0 # CS time t_MAC = 0 # MAC time t_MAC_mean = 0 # MAC average time packet_i=0 # Packets sent counter n_sensing = 0 # Number of CS performed # 'State' controls the state of the MAC State = "IDLE" # Initial Conditions of the Finite State Machine NAV = 0 # Network Allocation Vector N_RETRIES = 0 # Retries to send a packet counter busy_in_wfd = False # Busy in Wait_for_DIFS state BO_frozen = "NO" # Backoff frozen TX_attempts = 0 # Tries to send a packet counter CTS_failed = False # CTS reception failed chan = "FREE" # Channel state = IDDLE N_SEQ = 0 # Sequence number counter N_FRAG = 0 # Fragment number counter first_tx = True # Is the first attempt to send a packet? frag_count = 0 # Counter used during fragmentation data_temp_reass = "" # Initial variable to perform de re-assembly process verbose = True # Shows when the MAC is in 'IDDLE' state beaconing = False # Is ON the Beaconing process? fragmenting = 0 # Is the packet received a fragment? if options.V: print "=============================================" print " \t MAC layer: DCF + RTS/CTS" print "=============================================" print "MAC address:",MAC.which_dir(my_mac) print "Rate = ",options.regime print "tslot(s): %f \t SIFS(s): %f"%(tslot,SIFS) print "DIFS(s): %f \t T_ACK(s): %f"%(DIFS, ACK_time) print "pseudo-random exp. BACKOFF [%i,%i]"%(CW_min, CW_max) if options.RTS: print "RTS/CTS: enabled" print "\t with RTS Threshold(Bytes): %i \t" %RTS_THRESHOLD else: print "RTS/CTS: disabled" print "Fragmentation Threshold (Bytes):",dot11FragmentationTh if options.retx: print "Retransmissions: enabled" else: print "Retransmissions: disabled" print "Scaling time parameter = ",beta print "============================================="
print "MAC receives a BEACON from upper buffer......" beaconing = True if options.V: print "| IDLE | Transmit BEACON FRAME | WAIT_FOR_NAV |" State = "TRANSMITTING_RTS" elif reply_up == "NO": # is a CTS? print "Buffer has no DATA!!!....." reply_phy2, packet_phy2 = MAC.read_phy_response( PHY_port, "CTS") if reply_phy2 == "YES": verbose = True copied = packet_phy2 x = copied["INFO"] print "[R]-[%s]-[DA:%s]-[duration:%f]-[IFM:0]" % ( copied["HEADER"], MAC.which_dir( x["RX_add"]), x["txtime"]) tiempo = x["txtime"] / 1.0e3 if options.V: print "| IDLE | CTS captured (update NAV) | IDLE |" NAV = MAC.update_NAV(time.time(), tiempo, tslot) State = "IDLE" else: ##The following is newly added... reply_phy3, packet_phy3 = MAC.read_phy_response( PHY_port, "DATA") if reply_phy3 == "YES": WF_DATA_first_time = 1 State = "WAITING_FOR_DATA" if options.V: print "| IDLE | DATA received | WAITING_FOR_DATA |" #############################
''' #============================================================ # /TEST/ UNCOMMENT TO CHECK RTS/CTS FUNCTIONALITY #============================================================ # STEP 3/4: Node 1 --> DATA values = {"payload":"Paquete_que_llega12", "address1":x["mac_add1"], "address2":x["mac_add2"], "N_SEQ":N_SEQ, "N_FRAG":0, "timestamp":time.time()} DATA_forced = MAC.generate_pkt("DATA", options.interp, options.regime, values) packet_DATA_forced = MAC.create_packet("PKT", DATA_forced) MAC.transmit(packet_DATA_forced, PHY_port) time.sleep(2*tslot) #============================================================ ''' dest_mac = x["mac_add2"] if x["MF"]==0: #More Fragments = 0 if fragmenting == 0: # Not a fragmented packet print "[R]-[DATA]-[DA:%s]-[SA:%s]-[MF:0]-[IFM:1]-[PAYLOAD = %s]" %(MAC.which_dir(x["mac_add1"]),MAC.which_dir(x["mac_add2"]),x["PAYLOAD"]) if options.V: print "| WAITING_FOR_DATA | DATA received | TRANSMITTING_ACK |" State = "TRANSMITTING_ACK" WF_DATA_first_time = 1 frag_count = 0 MAC.send_ul_buff_packet(MAC_port, x["PAYLOAD"]) else: # Last fragmented packet fragmenting = 0 frag_count +=1 print "[R]-[FRAGMENTED DATA]-[DA:%s]-[SA:%s]-[MF:0]-[#seq:%i]-[#frag:%i]-[IFM:1]-[PAYLOAD = %s]" %(MAC.which_dir(x["mac_add2"]),MAC.which_dir(my_mac),x["N_SEQ"],x["N_FRAG"],x["PAYLOAD"]) test_seq = x["N_FRAG"]+1 - frag_count if test_seq == 0: dato_leido = data_temp_reass + x["PAYLOAD"] State = "TRANSMITTING_ACK" WF_DATA_first_time = 1 frag_count = 0
def run(self): pkt = self.socket.recv(1000) paquete_llegada = pickle.loads(pkt) # MAC requests an incoming packet to the PHY if (paquete_llegada["TIPO"]=="COLA"): tipo_pkt = paquete_llegada["DATOS"] len_data = self.data.longitud() len_ack = self.ack.longitud() len_rts = self.rts.longitud() len_cts = self.cts.longitud() if (tipo_pkt == "DATA") and len_data>0: # There are Data packets? self.data.elementos.reverse() x=self.data.read(0) phy_pkt = plcp.crear_paquete("SI",x) self.data.pop() self.data.elementos.reverse() elif tipo_pkt == "ACK" and len_ack>0: # There are ACK packets? self.ack.elementos.reverse() x=self.ack.read(0) phy_pkt = plcp.crear_paquete("SI",x) self.ack.pop() self.ack.elementos.reverse() elif tipo_pkt == "RTS" and len_rts>0: # There are RTS packets? self.rts.elementos.reverse() x=self.rts.read(0) phy_pkt = plcp.crear_paquete("SI",x) self.rts.pop() self.rts.elementos.reverse() elif tipo_pkt == "CTS" and len_cts>0: # There are CTS packets? self.cts.elementos.reverse() x=self.cts.read(0) phy_pkt = plcp.crear_paquete("SI",x) self.cts.pop() self.cts.elementos.reverse() else: # There are not packets phy_pkt = plcp.crear_paquete("NO",[]) plcp.enviar_a_mac(self.socket,phy_pkt) # Send the result (PHY packet) to MAC layer self.socket.close() # PHY packet generator script. It sends an 802.11 frame simulating its arrival from the wireless medium if (paquete_llegada["TIPO"]=="DATA" or paquete_llegada["TIPO"]=="DATA_FRAG"): if paquete_llegada["DATOS"]["INFO"]["mac_add1"] == self.my_mac: # Is the data packet addressed to this node? self.data.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"]=="ACK"): if paquete_llegada["DATOS"]["INFO"]["RX_add"] == self.my_mac:# Is the ACK addressed to this node? self.ack.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"]=="RTS"): #It is a RTS self.rts.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"]=="CTS"): #It is a CTS self.cts.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"]=="BEACON"): #It is a BEACON beacon = paquete_llegada["DATOS"] beacon = beacon["INFO"] msg = plcp.nuevo_beacon() msg["MAC"]= beacon["mac_add2"] msg["timestamp"]=beacon["timestamp"] msg["BI"]=beacon["BI"] msg["OFFSET"]=time.time() - beacon["timestamp"] x = self.bcn.longitud() actualizado = False # Update the beacon list for i in range(0,x): if msg["MAC"]==self.bcn.read(i)["MAC"]: self.bcn.quitar(i) self.bcn.insert(i,msg) actualizado = True if actualizado == False: self.bcn.insert(x+1,msg) if (paquete_llegada["TIPO"]=="OTHER"): #print "No packet arrived" self.socket.close() #DEBUG print "=========== BUFFER STATUS ===========" print "DATA [%i]"%self.data.longitud() print "ACK [%i]"%self.ack.longitud() print "RTS [%i]"%self.rts.longitud() print "CTS [%i]"%self.cts.longitud() print "=====================================" print "\n\n" # Beacon list print "========= NEIGHBOR NODES INFORMATION ==========" for i in range (0,self.bcn.longitud()): leido = self.bcn.read(i) print "[MAC = %s]\t [Timestamp = %s]\t [Beacon Interval = %s]\t [OFFSET = %s]" %(mac.which_dir(leido["MAC"]),leido["timestamp"],leido["BI"],leido["OFFSET"]) print "==============================================="
def RX_Client(options,my_mac,phy_rx_server): phy_rx_client, phy_rx_addr = phy_rx_server.accept() while 1: #phy_rx_client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #phy_rx_client.connect((socket.gethostname(), options.PHYRXport)) # PHY 802.11 frame arrival from the wireless medium pkt = phy_rx_client.recv(10000) arrived_packet=mac.parse_mac(pkt) if (arrived_packet["HEADER"]=="DATA" or arrived_packet["HEADER"]=="DATA_FRAG"): if arrived_packet["DATA"]["INFO"]["mac_add1"] == my_mac: # Is the data packet addressed to this node? data.push(arrived_packet["DATA"]) else: other.push("random data") if (arrived_packet["HEADER"]=="ACK"): if arrived_packet["DATA"]["INFO"]["RX_add"] == my_mac:# Is the ACK addressed to this node? ack.push(arrived_packet["DATA"]) if (arrived_packet["HEADER"]=="RTS"): #It is a RTS rts.push(arrived_packet["DATA"]) if (arrived_packet["HEADER"]=="CTS"): #It is a CTS cts.push(arrived_packet["DATA"]) if (arrived_packet["HEADER"]=="BEACON"): #It is a BEACON beacon = arrived_packet["DATA"] beacon = beacon["INFO"] msg = plcp.new_beacon() msg["MAC"]= beacon["mac_add2"] msg["timestamp"]=beacon["timestamp"] msg["BI"]=beacon["BI"] msg["OFFSET"]=time.time() - beacon["timestamp"] x = bcn.length() updated = False # Update the beacon list for i in range(0,x): if msg["MAC"]==bcn.read(i)["MAC"]: bcn.remove(i) bcn.insert(i,msg) updated = True if updated == False: bcn.insert(x+1,msg) if (arrived_packet["HEADER"]==""): print "No packet arrived" #DEBUG print "=========== BUFFER STATUS ===========" print "DATA [%i]"%data.length() print "ACK [%i]"%ack.length() print "RTS [%i]"%rts.length() print "CTS [%i]"%cts.length() print "OTHER [%i]"%other.length() print "=====================================" print "\n\n" # Beacon list print "========= NEIGHBOR NODES INFORMATION ==========" for i in range (0,bcn.length()): item = bcn.read(i) print "[MAC = %s]\t [Timestamp = %s]\t [Beacon Interval = %s]\t [OFFSET = %s]" %(mac.which_dir(item["MAC"]),item["timestamp"],item["BI"],item["OFFSET"]) print "===============================================" phy_rx_client.close()
def run(self): pkt = self.socket.recv(1000) paquete_llegada = pickle.loads(pkt) # MAC requests an incoming packet to the PHY if (paquete_llegada["TIPO"] == "COLA"): tipo_pkt = paquete_llegada["DATOS"] len_data = self.data.longitud() len_ack = self.ack.longitud() len_rts = self.rts.longitud() len_cts = self.cts.longitud() if (tipo_pkt == "DATA") and len_data > 0: # There are Data packets? self.data.elementos.reverse() x = self.data.read(0) phy_pkt = plcp.crear_paquete("SI", x) self.data.pop() self.data.elementos.reverse() elif tipo_pkt == "ACK" and len_ack > 0: # There are ACK packets? self.ack.elementos.reverse() x = self.ack.read(0) phy_pkt = plcp.crear_paquete("SI", x) self.ack.pop() self.ack.elementos.reverse() elif tipo_pkt == "RTS" and len_rts > 0: # There are RTS packets? self.rts.elementos.reverse() x = self.rts.read(0) phy_pkt = plcp.crear_paquete("SI", x) self.rts.pop() self.rts.elementos.reverse() elif tipo_pkt == "CTS" and len_cts > 0: # There are CTS packets? self.cts.elementos.reverse() x = self.cts.read(0) phy_pkt = plcp.crear_paquete("SI", x) self.cts.pop() self.cts.elementos.reverse() else: # There are not packets phy_pkt = plcp.crear_paquete("NO", []) plcp.enviar_a_mac( self.socket, phy_pkt) # Send the result (PHY packet) to MAC layer self.socket.close() # PHY packet generator script. It sends an 802.11 frame simulating its arrival from the wireless medium if (paquete_llegada["TIPO"] == "DATA" or paquete_llegada["TIPO"] == "DATA_FRAG"): if paquete_llegada["DATOS"]["INFO"][ "mac_add1"] == self.my_mac: # Is the data packet addressed to this node? self.data.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"] == "ACK"): if paquete_llegada["DATOS"]["INFO"][ "RX_add"] == self.my_mac: # Is the ACK addressed to this node? self.ack.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"] == "RTS"): #It is a RTS self.rts.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"] == "CTS"): #It is a CTS self.cts.push(paquete_llegada["DATOS"]) self.socket.close() if (paquete_llegada["TIPO"] == "BEACON"): #It is a BEACON beacon = paquete_llegada["DATOS"] beacon = beacon["INFO"] msg = plcp.nuevo_beacon() msg["MAC"] = beacon["mac_add2"] msg["timestamp"] = beacon["timestamp"] msg["BI"] = beacon["BI"] msg["OFFSET"] = time.time() - beacon["timestamp"] x = self.bcn.longitud() actualizado = False # Update the beacon list for i in range(0, x): if msg["MAC"] == self.bcn.read(i)["MAC"]: self.bcn.quitar(i) self.bcn.insert(i, msg) actualizado = True if actualizado == False: self.bcn.insert(x + 1, msg) if (paquete_llegada["TIPO"] == "OTHER"): #print "No packet arrived" self.socket.close() #DEBUG print "=========== BUFFER STATUS ===========" print "DATA [%i]" % self.data.longitud() print "ACK [%i]" % self.ack.longitud() print "RTS [%i]" % self.rts.longitud() print "CTS [%i]" % self.cts.longitud() print "=====================================" print "\n\n" # Beacon list print "========= NEIGHBOR NODES INFORMATION ==========" for i in range(0, self.bcn.longitud()): leido = self.bcn.read(i) print "[MAC = %s]\t [Timestamp = %s]\t [Beacon Interval = %s]\t [OFFSET = %s]" % ( mac.which_dir(leido["MAC"]), leido["timestamp"], leido["BI"], leido["OFFSET"]) print "==============================================="
""" Starts the MAC operation """ while 1: #IDLE STATE if State == "IDLE": # Is a RTS? reply_phy1, packet_phy1 = MAC.read_phy_response(PHY_port, "RTS") #print State if reply_phy1 == "YES": verbose = True # Show when the MAC is IDLE copied = packet_phy1 # Copy the received packet from the PHY x = copied["INFO"] # Copy the 802.11 frame included in the received packet from PHY if my_mac == x["RX_add"]: print "[R]-[%s]-[DA: %s]-[SA: %s]-[duration: %f]-[IFM:1]" %(copied["HEADER"],MAC.which_dir(x["RX_add"]),MAC.which_dir(x["TX_add"]),x["txtime"]) dest_mac = (x["TX_add"]) # Receiver Address of the CTS frame RTS_duration = x["txtime"] # Value of RTS' TX time if options.V: print "| IDLE | RTS received | TRANSMITTING_CTS |" """ #============================================================ # /TEST/ UNCOMMENT TO CHECK RTS/CTS FUNCTIONALITY #============================================================ # STEP 1/4: Node 1 --> RTS values = {"duration":x["txtime"], "mac_ra":x["RX_add"], "mac_ta":x["TX_add"], "timestamp":time.time()} RTS_forced = MAC.generate_pkt("RTS", options.interp, options.regime, values) packet_RTS_forced = MAC.create_packet("PKT", RTS_forced) MAC.transmit(packet_RTS_forced, PHY_port) time.sleep(tslot) #============================================================ """