Exemple #1
0
    def __get_packet_base(self, tc, pktspec):
        if pktspec.clone:
            if objects.IsReference(self.pktspec.clone):
                basepkt = self.pktspec.clone.Get(tc)
            elif objects.IsCallback(self.pktspec.clone):
                basepkt = self.pktspec.clone.call(tc, self)
            self.Clone(basepkt)

            if pktspec.paddingsize != 0:
                self.pktspec.paddingsize = pktspec.paddingsize
            if objects.IsCallback(self.pktspec.paddingsize):
                self.pktspec.paddingsize = self.pktspec.paddingsize.call(
                    tc, self)
            if objects.IsReference(self.pktspec.paddingsize):
                self.pktspec.paddingsize = self.pktspec.paddingsize.Get(tc)
            self.basepkt = basepkt

            # Special handling for ICRC inheritance.
            # ICRC is not carried in the hdrsorder metadata,
            # hence it must be explicitly inherited. Current 'icrc'
            # knob is used to calculate new icrc for this packet.
            # Hence adding a new knob for inherit case.
            self.inherit_icrc = False
            if self.basepkt.icrc is True and pktspec.icrc is False:
                self.inherit_icrc = True
            self.icrc = pktspec.icrc
            return

        if objects.IsReference(self.pktspec.paddingsize):
            self.pktspec.paddingsize = self.pktspec.paddingsize.Get(tc)
        if objects.IsCallback(self.pktspec.paddingsize):
            self.pktspec.paddingsize = self.pktspec.paddingsize.call(tc, self)

        if pktspec.template == None:
            logger.error("No Template or Clone specified for packet.")
            return None

        if objects.IsReference(pktspec.template):
            self.template = pktspec.template.Get(FactoryStore)
        elif objects.IsCallback(pktspec.template):
            self.template = pktspec.template.call(tc, self)
        else:
            assert (0)
        if self.template == None:
            logger.error("Template NOT FOUND for ID:%s" %\
                            self.spec.template.GetInstID())
            assert (self.template != None)
        return
Exemple #2
0
 def __resolve(self, obj, attr, default):
     curr = getattr(obj, attr, None)
     value = curr
     if curr is None:
         value = default
     elif objects.IsReference(curr):
         value = curr.Get(self)
     elif objects.IsCallback(curr):
         value = self.__resolve_by_callback(curr, default)
         value = value & 0xffffffff
     setattr(obj, attr, value)
     return
Exemple #3
0
 def __build(self, obj, testcase, packet):
     for key, data in obj.__dict__.items():
         if objects.IsReference(data):
             if data.GetRootID() == defs.ref_roots.TESTCASE:
                 obj.__dict__[key] = data.Get(testcase)
             elif data.GetRootID() == defs.ref_roots.FACTORY:
                 obj.__dict__[key] = data.Get(FactoryStore)
         elif objects.IsCallback(data):
             retval = data.call(testcase, packet)
             obj.__dict__[key] = obj.__get_field_value(retval)
         elif isinstance(data, list):
             self.__build_list(data, testcase, packet)
     return
Exemple #4
0
def __get_mff(tc, prefix, default):
    lkplabel = __get_lookup_label(tc, prefix)
    if lkplabel in MFFS:
        val = MFFS[lkplabel]
    else:
        val = default

    if type(val) is not str:
        return val

    if objects.IsTemplateFieldString(val):
        obj = objects.TemplateFieldObject(val)
        if objects.IsReference(obj):
            return obj.Get(tc)
        else:
            assert (0)
    return val
Exemple #5
0
    def __get_field_value(self, data):
        if not objects.IsFrameworkFieldObject(data):
            return data

        if IsVariableSizedField(data):
            return data

        if objects.IsAutoField(data):
            return None

        if objects.IsReference(data):
            # This will be resolved in 2nd phase.
            return data

        if objects.IsCallback(data):
            # This will be resolved in 2nd phase.
            return data

        return data.get()
Exemple #6
0
def __resolve_refs_obj(obj, tc):
    if obj is None:
        return
    for a, v in obj.__dict__.items():
        if objects.IsReference(v):
            val = v.Get(tc)
            logger.info("Resolving spec.fields.%s = " % a, val)
            obj.__dict__[a] = val
        elif objects.IsCallback(v):
            val = v.call(tc, obj)
            logger.info("Resolving spec.fields.%s = " % a, val)
            obj.__dict__[a] = val
        elif isinstance(v, list):
            __resolve_refs_list(v, tc)
        elif objects.IsFrameworkTemplateObject(v):
            __resolve_refs_obj(v, tc)
        else:
            # Native types
            continue
    return
Exemple #7
0
    def __get_payload_size(self, tc):
        if self.spec.payloadsize == None:
            return
        size = 0
        spec_size = self.spec.payloadsize
        if objects.IsReference(spec_size):
            if spec_size.GetRootID() == defs.ref_roots.FACTORY:
                size = spec_size.Get(FactoryStore)
            elif spec_size.GetRootID() == defs.ref_roots.TESTCASE:
                size = spec_size.Get(tc)
            else:
                assert (0)
        elif objects.IsCallback(spec_size):
            size = spec_size.call(tc, self)
        elif objects.IsFrameworkFieldObject(spec_size):
            size = spec_size.get()
        else:
            size = spec_size

        self.payloadsize = size
        return
Exemple #8
0
    def __add_payload(self, tc):
        if getattr(self.headers, 'payload', None) is None:
            self.payloadsize = 0
            return

        if self.GetPcap():
            self.payloadsize = 0
            return
        self.headers.payload.meta.size = self.payloadsize
        if self.headers.payload.fields.data is None:
            self.headers.payload.fields.data =\
                         self.headers.payload.meta.pattern.get(self.payloadsize)
        elif objects.IsCallback(self.headers.payload.fields.data):
            cb = self.headers.payload.fields.data
            self.headers.payload.fields.data = cb.call(tc, self)
            self.__fixup_payload(tc)
        elif objects.IsReference(self.headers.payload.fields.data):
            ref = self.headers.payload.fields.data
            if ref.GetRootID() == defs.ref_roots.FACTORY:
                data = ref.Get(FactoryStore)
            elif ref.GetRootID() == defs.ref_roots.TESTCASE:
                data = ref.Get(tc)
            else:
                assert (0)
            self.headers.payload.fields.data = list(data)
            self.__fixup_payload(tc)
        elif isinstance(self.headers.payload.fields.data, str):
            self.headers.payload.fields.data =\
                    utils.ParseIntegerList(self.headers.payload.fields.data)
        elif objects.IsFrameworkFieldObject(self.headers.payload.fields.data):
            self.headers.payload.fields.data =\
                    self.headers.payload.fields.data.get(self.payloadsize)
            self.__fixup_payload(tc)
        else:
            self.__fixup_payload(tc)
        logger.info("- Added Payload of Size = %d" % self.payloadsize)
        return