Beispiel #1
0
def test_fragment_bitmap_03():
    print("""## Figure 27 in draft-17""")
    N = 3
    WINDOW_SIZE = 7
    nb_tiles = 11
    tile_list = [
        {"w-num": 0, "t-num": 6, "nb_tiles": 1 },
        {"w-num": 0, "t-num": 5, "nb_tiles": 1 },
        #{"w-num": 0, "t-num": 4, "nb_tiles": 1 },
        {"w-num": 0, "t-num": 3, "nb_tiles": 1 },
        #{"w-num": 0, "t-num": 2, "nb_tiles": 1 },
        {"w-num": 0, "t-num": 1, "nb_tiles": 1 },
        {"w-num": 0, "t-num": 0, "nb_tiles": 1 },
        {"w-num": 1, "t-num": 6, "nb_tiles": 1 },
        {"w-num": 1, "t-num": 5, "nb_tiles": 1 },
        #{"w-num": 1, "t-num": 4, "nb_tiles": 1 },
        {"w-num": 1, "t-num": 7, "nb_tiles": 1 },
        ]

    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (0, BitBuffer([1, 1, 0, 1, 0, 1, 1])), 
        (1, BitBuffer([1, 1, 0, 0, 0, 0, 1]))
        ]
    check_bitmaps(bitmaps, expected)

    tile_list.append({"w-num": 0, "t-num": 4, "nb_tiles": 1 })
    tile_list.append({"w-num": 0, "t-num": 2, "nb_tiles": 1 })
    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (1, BitBuffer([1, 1, 0, 0, 0, 0, 1]))
        ]
    check_bitmaps(bitmaps, expected)

    tile_list.append({"w-num": 1, "t-num": 4, "nb_tiles": 1 })
    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (1, BitBuffer([1, 1, 1, 0, 0, 0, 1]))
        ]
    check_bitmaps(bitmaps, expected)
Beispiel #2
0
def test_fragment_bitmap_02():
    print("## find_missing_tiles:")
    tile_list = [
                { "w-num": 0, "t-num": 6, "nb_tiles": 3 },
                { "w-num": 0, "t-num": 3, "nb_tiles": 4 },
                { "w-num": 1, "t-num": 6, "nb_tiles": 3 },
                { "w-num": 1, "t-num": 3, "nb_tiles": 3 },
                { "w-num": 3, "t-num": 5, "nb_tiles": 2 },
                { "w-num": 3, "t-num": 7, "nb_tiles": 1 },
            ]
    bitmaps = find_missing_tiles(tile_list, 3, 7)
    expected = [
        (1, BitBuffer([1, 1, 1, 1, 1, 1, 0])),
        (2, BitBuffer([0, 0, 0, 0, 0, 0, 0])),
        (3, BitBuffer([0, 1, 1, 0, 0, 0, 1]))
        ]
    check_bitmaps(bitmaps, expected)
Beispiel #3
0
 def receive_frag(self, bbuf, dtag):
     schc_frag = schcmsg.frag_receiver_rx(self.rule, bbuf)
     print("receiver frag received:", schc_frag.__dict__)
     # XXX how to authenticate the message from the peer. without
     # authentication, any nodes can cancel the invactive timer.
     self.cancel_inactive_timer()
     #
     if schc_frag.abort == True:
         print("Received Sender-Abort.")
         # XXX needs to release all resources.
         return
     if self.state == "DONE":
         print("XXX need sending ACK back.")
         return
     # append the payload to the tile list.
     # padding truncation is done later. see below.
     nb_tiles = schc_frag.payload.count_added_bits(
     ) // self.rule["tileSize"]
     # Note that nb_tiles is the number of tiles which is exact number of the
     # size of the tile.  the tile of which the size is less than the size
     # is not included.
     self.tile_list.append({
         "w-num": schc_frag.win,
         "t-num": schc_frag.fcn,
         "nb_tiles": nb_tiles,
         "raw_tiles": schc_frag.payload
     })
     self.tile_list = sort_tile_list(self.tile_list, self.rule["FCNSize"])
     if self.mic_received is not None:
         schc_packet, mic_calced = self.get_mic_from_tiles_received()
         if self.mic_received == mic_calced:
             self.finish(schc_packet, schc_frag)
             return
         else:
             # XXX waiting for the fragments requested by ACK.
             # during MAX_ACK_REQUESTS
             print("waiting for more fragments.")
     elif schc_frag.fcn == schcmsg.get_fcn_all_1(self.rule):
         print("ALL1 received")
         self.mic_received = schc_frag.mic
         schc_packet, mic_calced = self.get_mic_from_tiles_received()
         if schc_frag.mic == mic_calced:
             self.finish(schc_packet, schc_frag)
             return
         else:
             print("ERROR: MIC mismatched. packet {} != result {}".format(
                 schc_frag.mic, mic_calced))
             bit_list = find_missing_tiles(self.tile_list,
                                           self.rule["FCNSize"],
                                           schcmsg.get_fcn_all_1(self.rule))
             assert bit_list is not None
             for bl_index in range(len(bit_list)):
                 print("missing wn={} bitmap={}".format(
                     bit_list[bl_index][0], bit_list[bl_index][1]))
                 # XXX compress bitmap if needed.
                 # ACK failure message
                 schc_ack = schcmsg.frag_receiver_tx_all1_ack(
                     schc_frag.rule,
                     schc_frag.dtag,
                     win=bit_list[bl_index][0],
                     cbit=0,
                     bitmap=bit_list[bl_index][1])
                 print("ACK failure sent:", schc_ack.__dict__)
                 args = (schc_ack.packet.get_content(),
                         self.context["devL2Addr"])
                 self.protocol.scheduler.add_event(
                     0, self.protocol.layer2.send_packet, args)
                 # XXX need to keep the ack message for the ack request.
     # set inactive timer.
     self.event_id_inactive_timer = self.protocol.scheduler.add_event(
         self.inactive_timer, self.event_inactive, tuple())
     print("---", schc_frag.fcn)
Beispiel #4
0
def test_fragment_bitmap_04():
    print("""## Figure 28 in draft-17""")
    N = 5 # all-1 = 31
    WINDOW_SIZE = 28
    tile_list = [
        {"w-num": 0, "t-num": 27, "nb_tiles": 4 },
        {"w-num": 0, "t-num": 23, "nb_tiles": 4 },
        {"w-num": 0, "t-num": 19, "nb_tiles": 4 },
        #{"w-num": 0, "t-num": 15, "nb_tiles": 4 },
        {"w-num": 0, "t-num": 11, "nb_tiles": 4 },
        {"w-num": 0, "t-num":  7, "nb_tiles": 4 },
        {"w-num": 0, "t-num":  3, "nb_tiles": 4 },
        {"w-num": 1, "t-num": 27, "nb_tiles": 4 },
        {"w-num": 1, "t-num": 23, "nb_tiles": 4 },
        {"w-num": 1, "t-num": 19, "nb_tiles": 4 },
        {"w-num": 1, "t-num": 15, "nb_tiles": 4 },
        {"w-num": 1, "t-num": 11, "nb_tiles": 4 },
        {"w-num": 1, "t-num":  7, "nb_tiles": 4 },
        #{"w-num": 1, "t-num":  3, "nb_tiles": 4 },
        {"w-num": 2, "t-num": 27, "nb_tiles": 4 },
        {"w-num": 2, "t-num": 23, "nb_tiles": 4 },
        {"w-num": 2, "t-num": 19, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 18, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 17, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 16, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 15, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 14, "nb_tiles": 1 },
        #{"w-num": 2, "t-num": 13, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 12, "nb_tiles": 1 },
        {"w-num": 2, "t-num": 31, "nb_tiles": 1 },
        ]

    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (0, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1])),
        (1, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 0, 0, 0, 0])),
        (2, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 1]))]
    check_bitmaps(bitmaps, expected)

    tile_list.append({"w-num": 0, "t-num": 15, "nb_tiles": 4 })
    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (1, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
                    1, 1, 1, 1, 0, 0, 0, 0])),
        (2, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 1]))]
    check_bitmaps(bitmaps, expected)

    tile_list.append({"w-num": 1, "t-num":  3, "nb_tiles": 4 })
    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (2, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 1]))]
    check_bitmaps(bitmaps, expected)

    tile_list.append({"w-num": 2, "t-num": 13, "nb_tiles": 1 })
    bitmaps = find_missing_tiles(tile_list, N, WINDOW_SIZE)
    expected = [
        (2, BitBuffer([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 1]))]
    check_bitmaps(bitmaps, expected)
            schc_packet, mic_calced = self.get_mic_from_tiles_received()
            print("schc_frag.mic: {}, mic_calced: {}".format(schc_frag.mic, mic_calced))
            if schc_frag.mic == mic_calced:
                print("SUCCESS: MIC matched. packet {} == result {}".format(
                    schc_frag.mic, mic_calced))
                self.mic_missmatched = False
                self.finish(schc_packet, schc_frag)
                return
            else:
                self.mic_missmatched = True
                self.state = 'ERROR_MIC'
                print("----------------------- ERROR -----------------------")
                print("ERROR: MIC mismatched. packet {} != result {}".format(
                    schc_frag.mic, mic_calced))
                bit_list = find_missing_tiles(self.tile_list,
                                              self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_FCN],
                                              schcmsg.get_fcn_all_1(self.rule))

                assert bit_list is not None

                schc_ack = self.create_ack_schc_ko(schc_frag)
                """
                Changement à corriger
                args = (schc_ack.packet.get_content(), self.context["devL2Addr"])
                """
                args = (schc_ack.packet.get_content(), '*')
                self.protocol.scheduler.add_event(
                    0, self.protocol.layer2.send_packet, args)
                # XXX need to keep the ack message for the ack request.
        # set inactive timer.
        self.event_id_inactive_timer = self.protocol.scheduler.add_event(
Beispiel #6
0
    def receive_frag(self, bbuf, dtag):

        print('state: {}, recieved fragment -> {}, rule-> {}'.format(
            self.state, bbuf, self.rule))

        schc_frag = schcmsg.frag_receiver_rx(self.rule, bbuf)
        print("receiver frag received:", schc_frag.__dict__)
        # XXX how to authenticate the message from the peer. without
        # authentication, any nodes can cancel the invactive timer.
        self.cancel_inactive_timer()
        if self.state == "ABORT":
            self.send_receiver_abort()
            return
        #
        #input("")
        if schc_frag.abort == True:
            print(
                "----------------------- Received Sender-Abort ---------------------------"
            )
            #Statsct.set_msg_type("SCHC_SENDER_ABORT")
            # XXX needs to release all resources.
            return

        if schc_frag.ack_request == True:
            print(
                "----------------------- Received ACK-REQ ---------------------------"
            )
            # if self.state != "DONE":
            #     #this can happen when the ALL-1 is not received, so the state is
            #     #not done and the sender is requesting an ACK.
            #     # sending Receiver abort.
            #     schc_frag = schcmsg.frag_receiver_tx_abort(self.rule, self.dtag)
            #     args = (schc_frag.packet.get_content(), self.context["devL2Addr"])
            #     print("Sent Receiver-Abort.", schc_frag.__dict__)
            #     print("----------------------- SCHC RECEIVER ABORT SEND  -----------------------")

            #     if enable_statsct:
            #         Statsct.set_msg_type("SCHC_RECEIVER_ABORT")
            #         #Statsct.set_header_size(schcmsg.get_sender_header_size(self.rule))
            #     self.protocol.scheduler.add_event(0,
            #                                 self.protocol.layer2.send_packet, args)
            #     # XXX needs to release all resources.
            #     return
            print("XXX need sending ACK back.")
            self.state = 'ACK_REQ'
            #input('')
            self.resend_ack(schc_frag)
            return

        self.fragment_received = True
        # append the payload to the tile list.
        # padding truncation is done later. see below.
        #nb_tiles = schc_frag.payload.count_added_bits()//self.rule["tileSize"]
        nb_tiles, last_tile_size = (schc_frag.payload.count_added_bits() //
                                    self.rule["tileSize"],
                                    schc_frag.payload.count_added_bits() %
                                    self.rule["tileSize"])
        print("---------nb_tiles: ", nb_tiles, " -----last_tile_size ",
              last_tile_size)
        tiles = [
            schc_frag.payload.get_bits_as_buffer(self.rule["tileSize"])
            for _ in range(nb_tiles)
        ]
        print("---------tiles: ", tiles)

        # Note that nb_tiles is the number of tiles which is exact number of the
        # size of the tile.  the tile of which the size is less than the size
        # is not included.
        # The tile that is less than a tile size must be included, so a 1 can be added
        # in the bitmap when there is a tile in the all-1 message

        win = schc_frag.win
        fcn = schc_frag.fcn
        for tile_in_tiles in tiles:
            idx = tiles.index(tile_in_tiles)
            if tile_in_tiles.count_added_bits() % self.rule["tileSize"] != 0:
                #tile found that is smaller than a normal tile
                print("tile found that is smaller than a normal tile")
                #nb_tiles = 1
            #tile should only be append if it is not in the list
            tile_in_list = False
            for tile in self.tile_list:
                if tile["w-num"] == win:
                    if tile["t-num"] == fcn - idx:
                        print("tile is already in tile list")
                        tile_in_list = True
            if not tile_in_list:
                self.tile_list.append({
                    "w-num": win,
                    "t-num": fcn - idx,
                    "nb_tiles": 1,
                    "raw_tiles": tile_in_tiles
                })
                self.tile_list = sort_tile_list(self.tile_list,
                                                self.rule["FCNSize"])
            if (fcn - idx) == 0:
                win += 1
                fcn = self.rule["FCNSize"] << 1
                tiles = tiles[(idx + 1):]

        if last_tile_size > 8:
            last_tile = schc_frag.payload.get_bits_as_buffer(last_tile_size)
            print('---------tile:', last_tile)
            tile_in_list = False
            for tile in self.tile_list:
                if tile["w-num"] == win:
                    if tile["t-num"] == 7:
                        print("tile is already in tile list")
                        tile_in_list = True
            if not tile_in_list:
                self.tile_list.append({
                    "w-num": win,
                    "t-num": 7,
                    "nb_tiles": 1,
                    "raw_tiles": last_tile
                })
                self.tile_list = sort_tile_list(self.tile_list,
                                                self.rule["FCNSize"])

        # if schc_frag.payload.count_added_bits()%self.rule["tileSize"] != 0:
        #     #tile found that is smaller than a normal tile
        #     print("tile found that is smaller than a normal tile")
        #     #nb_tiles = 1
        # #tile should only be append if it is not in the list
        # tile_in_list = False
        # for tile in self.tile_list:
        #     if tile["w-num"] == schc_frag.win:
        #         if tile["t-num"] == schc_frag.fcn:
        #             print("tile is already in tile list")
        #             tile_in_list = True
        # if not tile_in_list:
        #     self.tile_list.append({
        #             "w-num": schc_frag.win,
        #             "t-num": schc_frag.fcn,
        #             "nb_tiles": nb_tiles,
        #             "raw_tiles":schc_frag.payload})
        #     self.tile_list = sort_tile_list(self.tile_list, self.rule["FCNSize"])
        for tile in self.tile_list:
            print("w-num: {} t-num: {} nb_tiles:{}".format(
                tile['w-num'], tile['t-num'], tile['nb_tiles']))
        print("")
        #print("raw_tiles:{}".format(tile['raw_tiles']))
        #self.tile_list = sort_tile_list(self.tile_list, self.rule["WSize"])

        # self.tile_list.append({
        #         "w-num": schc_frag.win,
        #         "t-num": schc_frag.fcn,
        #         "nb_tiles": nb_tiles,
        #         "raw_tiles":schc_frag.payload})
        # self.tile_list = sort_tile_list(self.tile_list, self.rule["FCNSize"])
        #self.tile_list = sort_tile_list(self.tile_list, self.rule["WSize"])

        if self.mic_received is not None:
            schc_packet, mic_calced = self.get_mic_from_tiles_received()
            if self.mic_received == mic_calced:
                self.finish(schc_packet, schc_frag)
                return
            else:
                # XXX waiting for the fragments requested by ACK.
                # during MAX_ACK_REQUESTS
                print("waiting for more fragments.")
        elif schc_frag.fcn == schcmsg.get_fcn_all_1(self.rule):
            print(
                "----------------------- ALL1 received -----------------------"
            )
            self.all1_received = True
            Statsct.set_msg_type("SCHC_ALL_1")
            self.mic_received = schc_frag.mic
            schc_packet, mic_calced = self.get_mic_from_tiles_received()
            print("schc_frag.mic: {}, mic_calced: {}".format(
                schc_frag.mic, mic_calced))
            if schc_frag.mic == mic_calced:
                self.mic_missmatched = False
                self.finish(schc_packet, schc_frag)
                return
            else:
                self.mic_missmatched = True
                self.state = 'ERROR_MIC'
                print("----------------------- ERROR -----------------------")
                print("ERROR: MIC mismatched. packet {} != result {}".format(
                    schc_frag.mic, mic_calced))
                import warnings
                warnings.warn("[CA] XXX check here why git flipped this:")
                #bit_list = find_missing_tiles_mic_ko_yes_all_1(self.tile_list,
                bit_list = find_missing_tiles(self.tile_list,
                                              self.rule["FCNSize"],
                                              schcmsg.get_fcn_all_1(self.rule))

                assert bit_list is not None
                if len(bit_list) == 0:
                    #When the find_missing_tiles functions returns an empty array
                    #but we know something is missing because the MIC calculation is wrong
                    #this can happen when the first fragments are lost for example
                    print("bit list empty but the mic missmatched")
                    #if tiles are missing, then the packet is larger, should send a bitmap
                    #that considers the max_fcn and the tiles received
                    bit_list = find_missing_tiles_mic_ko_yes_all_1(
                        self.tile_list, self.rule["FCNSize"],
                        schcmsg.get_fcn_all_1(self.rule))
                    #print("new bit list, should it work???")
                    #input("")

                print(
                    "----------------------- SCHC ACK KO SEND 1 -----------------------"
                )
                for bl_index in range(len(bit_list)):
                    print("missing wn={} bitmap={}".format(
                        bit_list[bl_index][0], bit_list[bl_index][1]))
                    # XXX compress bitmap if needed.
                    # ACK failure message
                    schc_ack = schcmsg.frag_receiver_tx_all1_ack(
                        schc_frag.rule,
                        schc_frag.dtag,
                        win=bit_list[bl_index][0],
                        cbit=0,
                        bitmap=bit_list[bl_index][1])
                    if enable_statsct:
                        Statsct.set_msg_type("SCHC_ACK_KO")

                    print("ACK failure sent:", schc_ack.__dict__)
                    args = (schc_ack.packet.get_content(),
                            self.context["devL2Addr"])
                    self.protocol.scheduler.add_event(
                        0, self.protocol.layer2.send_packet, args)
                    # XXX need to keep the ack message for the ack request.
                    break  # problema con este break
        # set inactive timer.
        self.event_id_inactive_timer = self.protocol.scheduler.add_event(
            self.inactive_timer, self.event_inactive, tuple())
        print("---", schc_frag.fcn)
Beispiel #7
0
        ]
bit_list = make_bit_list(tile_list, 3, 7)
expected_list = {
    0: [1, 1, 1, 1, 1, 1, 1],
    1: [1, 1, 1, 1, 1, 1, 0],
    2: [0, 0, 0, 0, 0, 0, 0],
    3: [0, 1, 1, 0, 0, 0, 1],
    }

for i in bit_list.items():
    print(i)
assert bit_list == expected_list

#
print("## find_missing_tiles:")
bitmaps = find_missing_tiles(tile_list, 3, 7)
expected = [
    (1, BitBuffer([1, 1, 1, 1, 1, 1, 0])),
    (2, BitBuffer([0, 0, 0, 0, 0, 0, 0])),
    (3, BitBuffer([0, 1, 1, 0, 0, 0, 1]))
    ]
test_bitmaps(bitmaps, expected)

#
print("""## Figure 27 in draft-17""")
N = 3
WINDOW_SIZE = 7
nb_tiles = 11
tile_list = [
    {"w-num": 0, "t-num": 6, "nb_tiles": 1 },
    {"w-num": 0, "t-num": 5, "nb_tiles": 1 },
Beispiel #8
0
    def receive_frag(self, bbuf, dtag):

        print('state: {}, recieved fragment -> {}, rule-> {}'.format(
            self.state, bbuf, self.rule))

        schc_frag = schcmsg.frag_receiver_rx(self.rule, bbuf)
        print("receiver frag received:", schc_frag.__dict__)
        # XXX how to authenticate the message from the peer. without
        # authentication, any nodes can cancel the invactive timer.
        self.cancel_inactive_timer()
        if self.state == "ABORT":
            self.send_receiver_abort()
            return
        #
        # input("")
        if schc_frag.abort == True:
            print(
                "----------------------- Sender-Abort ---------------------------"
            )
            # Statsct.set_msg_type("SCHC_SENDER_ABORT")
            # XXX needs to release all resources.
            return

        if schc_frag.ack_request == True:
            print("Received ACK-REQ")
            # if self.state != "DONE":
            #     #this can happen when the ALL-1 is not received, so the state is
            #     #not done and the sender is requesting an ACK.
            #     # sending Receiver abort.
            #     schc_frag = schcmsg.frag_receiver_tx_abort(self.rule, self.dtag)
            #     args = (schc_frag.packet.get_content(), self.context["devL2Addr"])
            #     print("Sent Receiver-Abort.", schc_frag.__dict__)
            #     print("----------------------- SCHC RECEIVER ABORT SEND  -----------------------")

            #     if enable_statsct:
            #         Statsct.set_msg_type("SCHC_RECEIVER_ABORT")
            #         #Statsct.set_header_size(schcmsg.get_sender_header_size(self.rule))
            #     self.protocol.scheduler.add_event(0,
            #                                 self.protocol.layer2.send_packet, args)
            #     # XXX needs to release all resources.
            #     return
            print("XXX need sending ACK back.")
            self.state = 'ACK_REQ'
            # input('')
            self.resend_ack(schc_frag)
            return

        self.fragment_received = True
        # append the payload to the tile list.
        # padding truncation is done later. see below.
        # nb_tiles = schc_frag.payload.count_added_bits()//self.rule["tileSize"]
        tile_size = self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_TILE]
        nb_tiles, last_tile_size = (schc_frag.payload.count_added_bits() //
                                    tile_size,
                                    schc_frag.payload.count_added_bits() %
                                    tile_size)
        print("---------nb_tiles: ", nb_tiles, " -----last_tile_size ",
              last_tile_size)
        tiles = [
            schc_frag.payload.get_bits_as_buffer(tile_size)
            for _ in range(nb_tiles)
        ]
        print("---------tiles: ", tiles)

        # Note that nb_tiles is the number of tiles which is exact number of the
        # size of the tile.  the tile of which the size is less than the size
        # is not included.
        # The tile that is less than a tile size must be included, so a 1 can be added
        # in the bitmap when there is a tile in the all-1 message

        win = schc_frag.win
        fcn = schc_frag.fcn
        for tile_in_tiles in tiles:
            idx = tiles.index(tile_in_tiles)
            if tile_in_tiles.count_added_bits() % tile_size != 0:
                # tile found that is smaller than a normal tile
                print("tile found that is smaller than a normal tile")
                # nb_tiles = 1
            # tile should only be append if it is not in the list
            tile_in_list = False
            for tile in self.tile_list:
                if tile["w-num"] == win:
                    if tile["t-num"] == fcn - idx:
                        print("tile is already in tile list")
                        tile_in_list = True
            if not tile_in_list:
                self.tile_list.append({
                    "w-num": win,
                    "t-num": fcn - idx,
                    "nb_tiles": 1,
                    "raw_tiles": tile_in_tiles
                })
                self.tile_list = sort_tile_list(
                    self.tile_list, self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_FCN])
            if (fcn - idx) == 0:
                win += 1
                fcn = self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_FCN] << 1
                tiles = tiles[(idx + 1):]

        # !IMPORTANT: it's neccesary to change this condition for one more exact which consider the last tile size cases
        if last_tile_size > 8:
            last_tile = schc_frag.payload.get_bits_as_buffer(last_tile_size)
            print('---------tile:', last_tile)
            tile_in_list = False
            for tile in self.tile_list:
                if tile["w-num"] == win:
                    if tile["t-num"] == 7:
                        print("tile is already in tile list")
                        tile_in_list = True
            if not tile_in_list:
                self.tile_list.append({
                    "w-num": win,
                    "t-num": 7,
                    "nb_tiles": 1,
                    "raw_tiles": last_tile
                })
                self.tile_list = sort_tile_list(
                    self.tile_list, self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_FCN])

        # if schc_frag.payload.count_added_bits()%self.rule["tileSize"] != 0:
        #     #tile found that is smaller than a normal tile
        #     print("tile found that is smaller than a normal tile")
        #     #nb_tiles = 1
        # #tile should only be append if it is not in the list
        # tile_in_list = False
        # for tile in self.tile_list:
        #     if tile["w-num"] == schc_frag.win:
        #         if tile["t-num"] == schc_frag.fcn:
        #             print("tile is already in tile list")
        #             tile_in_list = True
        # if not tile_in_list:
        #     self.tile_list.append({
        #             "w-num": schc_frag.win,
        #             "t-num": schc_frag.fcn,
        #             "nb_tiles": nb_tiles,
        #             "raw_tiles":schc_frag.payload})
        #     self.tile_list = sort_tile_list(self.tile_list, self.rule["FCNSize"])
        for tile in self.tile_list:
            print("w-num: {} t-num: {} nb_tiles:{}".format(
                tile['w-num'], tile['t-num'], tile['nb_tiles']))
        print("")
        # print("raw_tiles:{}".format(tile['raw_tiles']))
        # self.tile_list = sort_tile_list(self.tile_list, self.rule["WSize"])

        # self.tile_list.append({
        #         "w-num": schc_frag.win,
        #         "t-num": schc_frag.fcn,
        #         "nb_tiles": nb_tiles,
        #         "raw_tiles":schc_frag.payload})
        # self.tile_list = sort_tile_list(self.tile_list, self.rule["FCNSize"])
        # self.tile_list = sort_tile_list(self.tile_list, self.rule["WSize"])

        if self.mic_received is not None:
            schc_packet, mic_calced = self.get_mic_from_tiles_received()
            if self.mic_received == mic_calced:
                self.finish(schc_packet, schc_frag)
                return
            else:
                # XXX waiting for the fragments requested by ACK.
                # during MAX_ACK_REQUESTS
                print("waiting for more fragments.")
        elif schc_frag.fcn == schcmsg.get_fcn_all_1(self.rule):
            print(
                "----------------------- ALL1 received -----------------------"
            )
            self.all1_received = True
            Statsct.set_msg_type("SCHC_ALL_1")
            self.mic_received = schc_frag.mic
            schc_packet, mic_calced = self.get_mic_from_tiles_received()
            print("schc_frag.mic: {}, mic_calced: {}".format(
                schc_frag.mic, mic_calced))
            if schc_frag.mic == mic_calced:
                print("SUCCESS: MIC matched. packet {} == result {}".format(
                    schc_frag.mic, mic_calced))
                self.mic_missmatched = False
                self.finish(schc_packet, schc_frag)
                return
            else:
                self.mic_missmatched = True
                self.state = 'ERROR_MIC'
                print("----------------------- ERROR -----------------------")
                print("ERROR: MIC mismatched. packet {} != result {}".format(
                    schc_frag.mic, mic_calced))
                bit_list = find_missing_tiles(
                    self.tile_list, self.rule[T_FRAG][T_FRAG_PROF][T_FRAG_FCN],
                    schcmsg.get_fcn_all_1(self.rule))

                assert bit_list is not None

                schc_ack = self.create_ack_schc_ko(schc_frag)
                """
                Changement à corriger
                args = (schc_ack.packet.get_content(), self.context["devL2Addr"])
                """
                args = (schc_ack.packet.get_content(), '*')
                self.protocol.scheduler.add_event(
                    0, self.protocol.layer2.send_packet, args)
                # XXX need to keep the ack message for the ack request.
        # set inactive timer.
        self.event_id_inactive_timer = self.protocol.scheduler.add_event(
            self.inactive_timer, self.event_inactive, tuple())
        print("---", schc_frag.fcn)