Example #1
0
 def __init__(self, rule, packet_bbuf):
     self.rule = rule
     #print('TileList()  Rule: ', rule)
     frag = rule["fragmentation"]
     ModProfil = frag["FRModeProfile"]
     tileSize = ModProfil["tileSize"]
     #print('tile size = ', tileSize)
     self.t_size = tileSize
     self.max_fcn = schcmsg.get_max_fcn(rule)
     self.all_tiles = []
     w_num = 0
     t_num = self.max_fcn
     # make tiles
     # XXX for now, the packet bitbuffer is going to be divided
     # into the tiles, which are a set of bit buffers too.
     # logically, it doesn't need when tileSize is well utilized.
     bbuf = packet_bbuf.copy()
     nb_full_size_tiles, last_tile_size = (bbuf.count_added_bits() //
                                           self.t_size,
                                           bbuf.count_added_bits() %
                                           self.t_size)
     assert last_tile_size >= 0
     tiles = [
         bbuf.get_bits_as_buffer(self.t_size)
         for _ in range(nb_full_size_tiles)
     ]
     if last_tile_size > 0:
         tiles.append(bbuf.get_bits_as_buffer(last_tile_size))
     # make a all_tiles
     for t in tiles:
         #print('w_num:', w_num,'  t_num:', t_num )
         tile_obj = {
             "w-num": w_num,
             "t-num": t_num,
             "tile": t,
             "sent": False,
         }
         self.all_tiles.append(tile_obj)
         if t_num == 0:
             t_num = self.max_fcn
             w_num += 1
         else:
             t_num -= 1
     if schcmsg.get_win_all_1(rule) < w_num:
         # win_all_1() is assumed to be equal to the max window number.
         raise ValueError("ERROR: the packet size > WSize. {} > {}".format(
             w_num, schcmsg.get_win_all_1(rule)))
     self.max_w_num = w_num
Example #2
0
 def __init__(self, rule, packet_bbuf):
     self.rule = rule
     """Changement à corriger 
     self.t_size = ["tileSize"]
     """
     self.t_size = rule[T_FRAG][T_FRAG_PROF][T_FRAG_TILE]
     self.max_fcn = schcmsg.get_max_fcn(rule)
     self.all_tiles = []
     w_num = 0
     t_num = self.max_fcn
     # make tiles
     # XXX for now, the packet bitbuffer is going to be divided
     # into the tiles, which are a set of bit buffers too.
     # logically, it doesn't need when tileSize is well utilized.
     bbuf = packet_bbuf.copy()
     nb_full_size_tiles, last_tile_size = (bbuf.count_added_bits() //
                                           self.t_size,
                                           bbuf.count_added_bits() %
                                           self.t_size)
     assert last_tile_size >= 0
     tiles = [
         bbuf.get_bits_as_buffer(self.t_size)
         for _ in range(nb_full_size_tiles)
     ]
     if last_tile_size > 0:
         tiles.append(bbuf.get_bits_as_buffer(last_tile_size))
     # make a all_tiles
     for t in tiles:
         tile_obj = {
             "w-num": w_num,
             "t-num": t_num,
             "tile": t,
             "sent": False,
         }
         self.all_tiles.append(tile_obj)
         if t_num == 0:
             t_num = self.max_fcn
             w_num += 1
         else:
             t_num -= 1
     if schcmsg.get_win_all_1(rule) < w_num:
         # win_all_1() is assumed to be equal to the max window number.
         raise ValueError("ERROR: the packet size > WSize. {} > {}".format(
             w_num, schcmsg.get_win_all_1(rule)))
     self.max_w_num = w_num
Example #3
0
 def receive_frag(self, schc_frag, dtag):
     # in No-Ack mode, only Receiver Abort message can be acceptable.
     print("sender frag received:", schc_frag.__dict__)
     if ((self.rule[T_FRAG][T_FRAG_PROF ][T_FRAG_W] is 0 or
          schc_frag.win == schcmsg.get_win_all_1(self.rule)) and
         schc_frag.cbit == 1 and schc_frag.remaining.allones() == True):
         print("Receiver Abort rid={} dtag={}".format(
                 self.rule.ruleID, self.dtag))
         return
     else:
         print("XXX Unacceptable message has been received.")
Example #4
0
    def receive_frag(self, bbuf, dtag):
        # the ack timer can be cancelled here, because it's been done whether
        # both rule_id and dtag in the fragment are matched to this session
        # at process_received_packet().
        self.cancel_ack_wait_timer(
        )  # the timeout is canceled but has to be set
        # when an ack should be received
        self.resend = False
        #
        schc_frag = schcmsg.frag_sender_rx(self.rule, bbuf)
        print(
            "-----------------------  Sender Frag Received -----------------------"
        )
        print("fragment received -> {}".format(schc_frag.__dict__))
        if ((self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_W] is None
             or schc_frag.win == schcmsg.get_win_all_1(self.rule))
                and schc_frag.cbit == 1
                and schc_frag.remaining.allones() == True):
            print(
                "-----------------------  Receiver Abort rid={} dtag={} -----------------------"
                .format(self.rule[T_RULEID], self.dtag))
            #self.resend = False
            self.state = self.RECEIVER_ABORT

            return
        if schc_frag.cbit == 1:
            print(
                "----------------------- ACK Success rid={} dtag={} -----------------------"
                .format(self.rule[T_RULEID], self.dtag))
            #self.resend = False
            self.state = self.ACK_SUCCESS

            try:
                f = open("client_server_simulation.txt", "r+")
            except IOError:
                f = open("client_server_simulation.txt", "w+")
                f = open("client_server_simulation.txt", "r+")
            content = f.read()
            seconds = time.time()
            f.seek(0, 0)
            f.write(str(int(seconds)) + '\n' + content)
            f.close()

            return
        if schc_frag.cbit == 0:
            print(
                "----------------------- ACK Failure rid={} dtag={} -----------------------"
                .format(self.rule[T_RULEID], self.dtag))
            #self.resend = False
            #self.all1_send = False
            self.state = self.ACK_FAILURE
            self.resend_frag(schc_frag)
            return
Example #5
0
    def receive_frag(self, bbuf, dtag):
        # the ack timer can be cancelled here, because it's been done whether
        # both rule_id and dtag in the fragment are matched to this session
        # at process_received_packet().
        self.cancel_ack_wait_timer(
        )  # the timeout is canceled but has to be set
        # when an ack should be received
        self.resend = False
        #
        schc_frag = schcmsg.frag_sender_rx(self.rule, bbuf)
        print(
            "-----------------------  sender frag received -----------------------"
        )
        print("fragment received -> {}".format(schc_frag.__dict__))
        if ((self.rule["WSize"] is None
             or schc_frag.win == schcmsg.get_win_all_1(self.rule))
                and schc_frag.cbit == 1
                and schc_frag.remaining.allones() == True):
            print(
                "-----------------------  Receiver Abort rid={} dtag={} -----------------------"
                .format(self.rule.ruleID, self.dtag))
            #self.resend = False
            self.state = self.RECEIVER_ABORT

            return
        if schc_frag.cbit == 1:
            print(
                "----------------------- ACK Success rid={} dtag={} -----------------------"
                .format(self.rule.ruleID, self.dtag))
            #self.resend = False
            self.state = self.ACK_SUCCESS
            return
        if schc_frag.cbit == 0:
            print(
                "----------------------- ACK Failure rid={} dtag={} -----------------------"
                .format(self.rule.ruleID, self.dtag))
            #self.resend = False
            #self.all1_send = False
            self.state = self.ACK_FAILURE
            self.resend_frag(schc_frag)
            return
Example #6
0
 def receive_frag(self, bbuf, dtag):
     # the ack timer can be cancelled here, because it's been done whether
     # both rule_id and dtag in the fragment are matched to this session
     # at process_received_packet().
     self.cancel_ack_wait_timer()
     #
     schc_frag = schcmsg.frag_sender_rx(self.rule, bbuf)
     print("sender frag received:", schc_frag.__dict__)
     if ((self.rule["WSize"] is None
          or schc_frag.win == schcmsg.get_win_all_1(self.rule))
             and schc_frag.cbit == 1
             and schc_frag.remaining.allones() == True):
         print("Receiver Abort rid={} dtag={}".format(
             self.rule.ruleID, self.dtag))
         return
     if schc_frag.cbit == 1:
         print("ACK Success rid={} dtag={}".format(self.rule.ruleID,
                                                   self.dtag))
         return
     if schc_frag.cbit == 0:
         print("ACK Failure rid={} dtag={}".format(self.rule.ruleID,
                                                   self.dtag))
         self.resend_frag(schc_frag)
         return