Beispiel #1
0
 def _update_v6_fields(self, source_obj, dest_obj):
     if not source_obj._next_header._is_default:
         dest_obj.is_override_next_header = True
         dest_obj.next_header = Converter.convertstring2int(
             source_obj._next_header.current_val)
     dest_obj.traffic_class = int(
         source_obj.traffic_class
     )  #int(Converter.remove_non_hexa_sumbols(hex(int(source_obj.traffic_class))))#Converter.convertstring2int(source_obj.traffic_class)
     dest_obj.hop_limit = int(
         source_obj.hop_limit)  #Converter.convertstring2int
     dest_obj.flow_label = Converter.convertstring2int(
         source_obj.flow_label)
     dest_obj.src_addr_hi, dest_obj.src_addr_lo = self._handle_v6(
         source_obj.source_ip.value)
     dest_obj.dst_addr_hi, dest_obj.dst_addr_lo = self._handle_v6(
         source_obj.destination_ip.value)
     dest_obj.src_addr_mode = OstinatoEnums.unified_to_ostinato(
         source_obj.source_ip.mode)
     dest_obj.src_addr_count = int(
         source_obj.source_ip.count
     ) if source_obj.source_ip.count != '0' else 1
     dest_obj.dst_addr_mode = OstinatoEnums.unified_to_ostinato(
         source_obj.destination_ip.mode)
     dest_obj.dst_addr_count = int(
         source_obj.destination_ip.count
     ) if source_obj.destination_ip.count != '0' else 1
     return dest_obj
Beispiel #2
0
 def _handle_v6(self, input):
     input = Converter.expand_ipv6(input)
     input = Converter.remove_non_hexa_sumbols(input)
     split = int(len(input) / 2)
     low = Converter.convertstring2int(input[split:])
     high = Converter.convertstring2int(input[:split])
     return high, low
Beispiel #3
0
    def create_gre_obj(cls, utg_gre):
        # type: (Packet.GRE) -> object
        obj = GRE()
        #bin_headers = '0x' + binascii.hexlify(obj.bin()).decode('utf-8')
        obj.version_number = utg_gre.version
        #bin_headers = '0x' + binascii.hexlify(obj.bin()).decode('utf-8')
        if utg_gre.use_checksum is True:
            obj.opts.append(GREOptionChecksum(checksum=0))
            obj.opts.append(GREOptionReserve_1())
            obj.checksum_bit = 1
        #bin_headers = '0x' + binascii.hexlify(obj.bin()).decode('utf-8')
        if utg_gre.key_field is not None:
            obj.opts.append(
                GREOptionKey(
                    key=Converter.convertstring2int(utg_gre.key_field)))
            obj.key_bit = 1
        #bin_headers = '0x' + binascii.hexlify(obj.bin()).decode('utf-8')
        if utg_gre.sequence_number is not None:
            obj.opts.append(
                GREOptionSequence(sequence=Converter.convertstring2int(
                    utg_gre.sequence_number)))
            obj.sequence_bit = 1
        #bin_headers = '0x' + binascii.hexlify(obj.bin()).decode('utf-8')
        if utg_gre.use_checksum is True:
            innerPacketData = obj.bin()
            if utg_gre.l3_proto is TGEnums.L3_PROTO.IPV4:
                obj.protocol_type = ETH_TYPE_IP
                packer_v4 = utg_gre.ipv4.to_packer()
                innerPacketData += packer_v4.bin()
            elif utg_gre.l3_proto is TGEnums.L3_PROTO.IPV6:
                obj.protocol_type = ETH_TYPE_IP6
                v6 = utg_gre.ipv6.to_packer()
                innerPacketData += v6.bin()
            else:
                proto = Converter.remove_non_hexa_sumbols(utg_gre.l3_proto)
                proto = Converter.hexaString2int(proto)
                obj.protocol_type = proto

            if utg_gre.l4_proto is TGEnums.L4_PROTO.UDP:
                packer_udp = utg_gre.udp.to_packer()
                innerPacketData += packer_udp.bin()
            elif utg_gre.l4_proto is TGEnums.L4_PROTO.TCP:
                packer_tcp = utg_gre.tcp.to_packer()
                innerPacketData += packer_tcp.bin()

            s = checksum.in_cksum(innerPacketData)
            obj.opts[0].checksum = s
        #bin_headers = '0x' + binascii.hexlify(obj.bin()).decode('utf-8')
        return obj
Beispiel #4
0
 def _apply_data_pattern(self):
     sp_obj = self._stream_driver_obj.frame  #type: StcStream()
     if self.packet.data_pattern.type is TGEnums.DATA_PATTERN_TYPE.FIXED:
         #!!! currently custom type not supported by 400G ,used custom header instead
         pl = Converter.remove_non_hexa_sumbols(
             self.packet.data_pattern.value)
         sp_obj.add_header(StcFrame_Layers.UpperLayerProtocols_II.Custom,
                           pattern=pl)
         #sp_obj.Payload.update_fields(pattern=self.packet.data_pattern.value)
         # pl = self.packet.data_pattern.value
         # res = ''
         # lst = pl.split()
         # for x in lst:
         #     r = Converter.convertstring2int(x)
         #     res += str(r)
         #     res += ' '
         # self._stream_driver_obj.frame.custom_pl(res)
         return
     elif self.packet.data_pattern.type is TGEnums.DATA_PATTERN_TYPE.INCREMENT_BYTE \
             or self.packet.data_pattern.type is TGEnums.DATA_PATTERN_TYPE.INCREMENT_WORD:
         fill_type = 'INCR'
         data = 0
     elif self.packet.data_pattern.type is TGEnums.DATA_PATTERN_TYPE.DECREMENT_BYTE\
             or self.packet.data_pattern.type is TGEnums.DATA_PATTERN_TYPE.DECREMENT_WORD:
         fill_type = 'DECR'
         data = 0
     elif self.packet.data_pattern.type is TGEnums.DATA_PATTERN_TYPE.REPEATING:
         fill_type = 'CONSTANT'
         int_pl = Converter.convertstring2int(
             self.packet.data_pattern.value)
         data = int_pl
     self._stream_driver_obj.set_attributes(FillType=fill_type,
                                            ConstantFillPattern=data)
Beispiel #5
0
 def _add_update_modifier(self,
                          field,
                          offset,
                          count=None,
                          mode=TGEnums.MODIFIER_UDF_REPEAT_MODE.UP,
                          initVal='0',
                          step=1):
     from xenavalkyrie.xena_stream import XenaModifierAction
     sMask = '0xFFFF0000'
     rep = 1
     smMaxVal = 0xFFFF
     startValue = Converter.convertstring2int(initVal)
     startValue &= 0xFFFF
     adapter = 1  #if step > 1 else 1
     if mode is TGEnums.MODIFIER_UDF_REPEAT_MODE.UP:
         mode = XenaModifierAction.increment
         minVal = startValue
         maxVal = smMaxVal - 1 if count is None else startValue + step * (
             count - adapter)
     else:
         mode = XenaModifierAction.decrement
         maxVal = startValue
         minVal = 0 if count is None else startValue - count * step + adapter
     if not field._driver_obj:
         field._driver_obj = self._stream_driver_obj.add_modifier(
             position=offset,
             mask=sMask,
             action=mode,
             repeat=rep,
             min_val=minVal,
             step=step,
             max_val=maxVal)
     else:
         field._driver_obj.update(position=offset,
                                  mask=sMask,
                                  action=mode,
                                  repeat=rep,
                                  min_val=minVal,
                                  step=step,
                                  max_val=maxVal)
Beispiel #6
0
 def init_vlan(utg_vlan, ost_vlan):
     ost_vlan.is_override_tpid = True
     ost_vlan.tpid = Converter.convertstring2int(utg_vlan.proto)
     priority = (int(utg_vlan.priority) << 13)
     cfi = (int(utg_vlan.cfi) << 12)
     ost_vlan.vlan_tag = int(utg_vlan.vid.value) + priority + cfi