import unittest
import struct

ie_type_length = {
    1: 1,
    2: 8,
    3: 6,
    4: 4,
    5: 4,
    8: 1,
    9: 28,
    11: 1,
    12: 3,
    13: 1,
    14: 1,
    15: 1,
    16: 4,
    17: 4,
    18: 5,
    19: 1,
    20: 1,
    21: 1,
    22: 9,
    23: 1,
    24: 1,
    25: 2,
    26: 2,
    27: 2,
    28: 2,
    29: 1,
    127: 4,
}


ie_name_to_type = {
    'Cause':                                     1,
    'IMSI':                                      2,
    'RAI':                                       3,
    'TLLI':                                      4,
    'P-TMSI':                                    5,
    'Reordering Required':                       8,
    'Authentication Triplet':                    9,
    'MAP Cause':                                 11,
    'P-TMSI Signature':                          12,
    'MS Validated':                              13,
    'Recovery':                                  14,
    'Selection Mode':                            15,
    'TEID Data I':                               16,
    'TEID Control Plane':                        17,
    'TEID Data II':                              18,
    'Teardown Ind':                              19,
    'NSAPI':                                     20,
    'RANAP Cause':                               21,
    'RAB Context':                               22,
    'Radio Priority SMS':                        23,
    'Radio Priority':                            24,
    'Packet Flow Id':                            25,
    'Charging Characteristics':                  26,
    'Trace Reference':                           27,
    'Trace Type':                                28,
    'MS Not Reachable Reason':                   29,
    'Charging ID':                               127,
    'End User Address':                          128,
    'MM Context':                                129,
    'PDP Context':                               130,
    'APN':                                       131,
    'Protocol Configuration Options':            132,
    'GSN Address':                               133,
    'MSISDN':                                    134,
    'QoS Profile':                               135,
    'Authentication Quintuplet':                 136,
    'Traffic Flow Template':                     137,
    'Target Identification':                     138,
    'UTRAN Transparent Container':               139,
    'RAB Setup Information':                     140,
    'Extension Header Type List':                141,
    'Trigger Id':                                142,
    'OMC Identity':                              143,
    'RAN Transparent Container':                 144,
    'PDP Context Prioritization':                145,
    'Additional RAB Setup Information':          146,
    'SGSN Number':                               147,
    'Common Flags':                              148,
    'APN Restriction':                           149,
    'Radio Priority LCS':                        150,
    'RAT Type':                                  151,
    'User Location Information':                 152,
    'MS Time Zone':                              153,
    'IMEI':                                      154,
    'CAMEL Charging Information Container':      155,
    'MBMS UE Context':                           156,
    'TMGI':                                      157,
    'RIM Routing Address':                       158,
    'MBMS Protocol Configuration Options':       159,
    'MBMS Service Area':                         160,
    'Source RNC PDCP context info':              161,
    'Additional Trace Info':                     162,
    'Hop Counter':                               163,
    'Selected PLMN ID':                          164,
    'MBMS Session Identifier':                   165,
    'MBMS 2G/3G Indicator':                      166,
    'Enhanced NSAPI':                            167,
    'MBMS Session Duration':                     168,
    'Additional MBMS Trace Info':                169,
    'MBMS Session Repetition Number':            170,
    'MBMS Time To Data Transfer':                171,
    'BSS Container':                             173,
    'Cell Identification':                       174,
    'PDU Numbers':                               175,
    'BSSGP Cause':                               176,
    'Required MBMS bearer capabilities':         177,
    'RIM Routing Address Discriminator':         178,
    'List of set-up PFCs':                       179,
    'PS Handover XID Parameters':                180,
    'MS Info Change Reporting Action':           181,
    'Direct Tunnel Flags':                       182,
    'Correlation-ID':                            183,
    'Bearer Control Mode':                       184,
    'MBMS Flow Identifier':                      185,
    'MBMS IP Multicast Distribution':            186,
    'MBMS Distribution Acknowledgement':         187,
    'Reliable INTER RAT HANDOVER INFO ':         188,
    'RFSP Index':                                189,
    'FQDN':                                      190,
    'Evolved Allocation/Retention Priority I':   191,
    'Evolved Allocation/Retention Priority II':  192,
    'Extended Common Flags':                     193,
    'UCI':                                       194,
    'CSG Information Reporting Action':          195,
    'CSG ID':                                    196,
    'CMI':                                       197,
    'AMBR':                                      198,
    'UE Network Capability':                     199,
    'UE-AMBR':                                   200,
    'APN-AMBR with NSAPI':                       201,
    'GGSN Back-Off Time':                        202,
    'Signalling Priority Indication':            203,
    'Signalling Priority Indication with NSAPI': 204,
    'Higher bitrates than 16 Mbps flag':         205,
    'Additional MM context for SRVCC':           207,
    'Additional flags for SRVCC':                208,
    'STN-SR':                                    209,
    'C-MSISDN':                                  210,
    'Extended RANAP Cause':                      211,
    'eNodeB ID':                                 212,
    'Selection Mode with NSAPI':                 213,
    'ULI Timestamp':                             214,
    'Local Home Network ID (LHN-ID) with NSAPI': 215,
    'CN Operator Selection Entity    ':          216,
    'UE Usage Type':                             217,
    'Extended Common Flags II':                  218,
    'Node Identifier ':                          219,
    'CIoT Optimizations Support Indication':     220,
    'SCEF PDN Connection':                       221,
    'IOV_updates counter':                       222,
    'Special IE type for IE Type Extension':     238,
    'Charging Gateway Address':                  251,
}


ie_types = {
    1: "u8",
    2: "octetstring",
    3: "octetstring",
    4: "u32",
    5: "u32",
    8: "u8",
    9: "octetstring",
    11: "u8",
    12: "octetstring",
    13: "u8",
    14: "u8",
    15: "u8",
    16: "u32",
    17: "u32",
    18: "octetstring",
    19: "u8",
    20: "u8",
    21: "u8",
    22: "octetstring",
    23: "u8",
    24: "u8",
    25: "u16",
    26: "u16",
    27: "u16",
    28: "u16",
    29: "u8",
    127: "u32",
    128: "octetstring",
    129: "octetstring",
    130: "octetstring",
    131: "octetstring",
    132: "octetstring",
    133: "octetstring",
    134: "octetstring",
    135: "octetstring",