Beispiel #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
Beispiel #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
Beispiel #3
0
    def __get_packet_encaps(self, tc, pktspec):
        if pktspec.encaps == None:
            return

        if objects.IsCallback(pktspec.encaps):
            self.encaps = pktspec.encaps.call(tc, self)
            return

        for encspec in pktspec.encaps:
            encap = encspec.Get(FactoryStore)
            self.encaps.append(encap)
        return
Beispiel #4
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
Beispiel #5
0
    def __scale_up(self):
        scale_factor = getattr(self, 'scale_factor', None)
        if objects.IsCallback(scale_factor):
            scale_factor = scale_factor.call()

        if scale_factor is None:
            return

        self.scale_factor = scale_factor
        self.__scale_up_objects_section()
        self.__scale_up_trig_exp_section(self.trigger)
        self.__scale_up_trig_exp_section(self.expect)
        return
Beispiel #6
0
 def __verify_descriptors(self, step, tc):
     final_status = defs.status.SUCCESS
     for dsp in step.expect.descriptors:
         negtest_obj = dsp.descriptor.negtest
         if objects.IsCallback(negtest_obj):
             negtest = negtest_obj.call(tc)
         else:
             negtest = negtest_obj
         edescr = dsp.descriptor.object
         adescr = self.__consume_descriptor(edescr, negtest,
                                            dsp.descriptor.ring, tc)
         status = self.__verify_one_descriptor(edescr, adescr, negtest, tc)
         if status == defs.status.ERROR:
             final_status = status
     return final_status
Beispiel #7
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()
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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