def update_ip_packet(self, traffic): """Update the IP packet NOTE: Only IPv4 is currently supported. :param traffic: list of traffic elements; each traffic element contains the injection parameter for each flow group. """ # NOTE(ralonsoh): L4 configuration is not set. for traffic_param in traffic.values(): fg_id = str(traffic_param['id']) if not self._get_config_element_by_flow_group_name(fg_id): raise exceptions.IxNetworkFlowNotPresent(flow_group=fg_id) if traffic_param['outer_l3']: count = traffic_param['outer_l3']['count'] srcip = traffic_param['outer_l3']['srcip'] dstip = traffic_param['outer_l3']['dstip'] srcseed = traffic_param['outer_l3']['srcseed'] dstseed = traffic_param['outer_l3']['dstseed'] srcmask = traffic_param['outer_l3']['srcmask'] \ or ipaddress.IPV4LENGTH dstmask = traffic_param['outer_l3']['dstmask'] \ or ipaddress.IPV4LENGTH if srcip: self._update_ipv4_address( self._get_stack_item(fg_id, PROTO_IPV4)[0], 'srcIp', str(srcip), srcseed, srcmask, count) if dstip: self._update_ipv4_address( self._get_stack_item(fg_id, PROTO_IPV4)[0], 'dstIp', str(dstip), dstseed, dstmask, count)
def update_l4(self, traffic): """Update the L4 headers NOTE: Only UDP is currently supported :param traffic: list of traffic elements; each traffic element contains the injection parameter for each flow group """ for traffic_param in traffic.values(): fg_id = str(traffic_param['id']) if not self._get_config_element_by_flow_group_name(fg_id): raise exceptions.IxNetworkFlowNotPresent(flow_group=fg_id) proto = traffic_param['outer_l3']['proto'] if proto not in SUPPORTED_PROTO: raise exceptions.IXIAUnsupportedProtocol(protocol=proto) count = traffic_param['outer_l4']['count'] seed = traffic_param['outer_l4']['seed'] srcport = traffic_param['outer_l4']['srcport'] srcmask = traffic_param['outer_l4']['srcportmask'] dstport = traffic_param['outer_l4']['dstport'] dstmask = traffic_param['outer_l4']['dstportmask'] if proto in SUPPORTED_PROTO: self._update_udp_port( self._get_stack_item(fg_id, proto)[0], 'srcPort', srcport, seed, srcmask, count) self._update_udp_port( self._get_stack_item(fg_id, proto)[0], 'dstPort', dstport, seed, dstmask, count)
def update_frame(self, traffic): """Update the L2 frame This function updates the L2 frame options: - Traffic type: "continuous", "fixedDuration". - Duration: in case of traffic_type="fixedDuration", amount of seconds to inject traffic. - Rate: in frames per seconds or percentage. - Type of rate: "framesPerSecond" ("bitsPerSecond" and "percentLineRate" no used) - Frame size: custom IMIX [1] definition; a list of packet size in bytes and the weight. E.g.: [64, 10, 128, 15, 512, 5] [1] https://en.wikipedia.org/wiki/Internet_Mix :param traffic: list of traffic elements; each traffic element contains the injection parameter for each flow group. """ for traffic_param in traffic.values(): fg_id = str(traffic_param['id']) config_element = self._get_config_element_by_flow_group_name(fg_id) if not config_element: raise exceptions.IxNetworkFlowNotPresent(flow_group=fg_id) type = traffic_param.get('traffic_type', 'fixedDuration') duration = traffic_param.get('duration', 30) rate = traffic_param['iload'] weighted_range_pairs = self._parse_framesize( traffic_param['outer_l2']['framesize']) srcmac = str(traffic_param.get('srcmac', '00:00:00:00:00:01')) dstmac = str(traffic_param.get('dstmac', '00:00:00:00:00:02')) # NOTE(ralonsoh): add QinQ tagging when # traffic_param['outer_l2']['QinQ'] exists. # s_vlan = traffic_param['outer_l2']['QinQ']['S-VLAN'] # c_vlan = traffic_param['outer_l2']['QinQ']['C-VLAN'] self.ixnet.setMultiAttribute( config_element + '/transmissionControl', '-type', type, '-duration', duration) self.ixnet.setMultiAttribute(config_element + '/frameRate', '-rate', rate, '-type', 'framesPerSecond') self.ixnet.setMultiAttribute(config_element + '/frameSize', '-type', 'weightedPairs', '-weightedRangePairs', weighted_range_pairs) self.ixnet.commit() self._update_frame_mac( self._get_stack_item(fg_id, PROTO_ETHERNET)[0], 'destinationAddress', dstmac) self._update_frame_mac( self._get_stack_item(fg_id, PROTO_ETHERNET)[0], 'sourceAddress', srcmac)
def _get_stack_item(self, flow_group_name, protocol_name): """Return the stack item given the flow group name and the proto name :param flow_group_name: (str) flow group name :param protocol_name: (str) protocol name, referred to PROTO_* constants :return: list of stack item descriptors """ celement = self._get_config_element_by_flow_group_name(flow_group_name) if not celement: raise exceptions.IxNetworkFlowNotPresent( flow_group=flow_group_name) stack_items = self.ixnet.getList(celement, 'stack') return [s_i for s_i in stack_items if protocol_name in s_i]
def update_ip_packet(self, traffic): """Update the IP packet NOTE: Only IPv4 is currently supported. :param traffic: list of traffic elements; each traffic element contains the injection parameter for each flow group. """ # NOTE(ralonsoh): L4 configuration is not set. for traffic_param in traffic.values(): fg_id = str(traffic_param['id']) if not self._get_config_element_by_flow_group_name(fg_id): raise exceptions.IxNetworkFlowNotPresent(flow_group=fg_id) count = traffic_param['outer_l3']['count'] srcip4 = str(traffic_param['outer_l3']['srcip4']) dstip4 = str(traffic_param['outer_l3']['dstip4']) self._update_ipv4_address( self._get_stack_item(fg_id, PROTO_IPV4)[0], 'srcIp', srcip4, 1, IP_VERSION_4_MASK, count) self._update_ipv4_address( self._get_stack_item(fg_id, PROTO_IPV4)[0], 'dstIp', dstip4, 1, IP_VERSION_4_MASK, count)
def update_frame(self, traffic, duration): """Update the L2 frame This function updates the L2 frame options: - Traffic type: "continuous", "fixedDuration". - Duration: in case of traffic_type="fixedDuration", amount of seconds to inject traffic. - Rate: in frames per seconds or percentage. - Type of rate: "framesPerSecond" or "percentLineRate" ("bitsPerSecond" no used) - Frame size: custom IMIX [1] definition; a list of packet size in bytes and the weight. E.g.: [[64, 64, 10], [128, 128, 15], [512, 512, 5]] [1] https://en.wikipedia.org/wiki/Internet_Mix :param traffic: list of traffic elements; each traffic element contains the injection parameter for each flow group. :param duration: (int) injection time in seconds. """ for traffic_param in traffic.values(): fg_id = str(traffic_param['id']) config_element = self._get_config_element_by_flow_group_name(fg_id) if not config_element: raise exceptions.IxNetworkFlowNotPresent(flow_group=fg_id) type = traffic_param.get('traffic_type', 'fixedDuration') rate_unit = ('framesPerSecond' if traffic_param['rate_unit'] == tp_base.TrafficProfileConfig.RATE_FPS else 'percentLineRate') weighted_range_pairs = self._parse_framesize( traffic_param['outer_l2'].get('framesize', {})) srcmac = str(traffic_param['outer_l2'].get('srcmac', '00:00:00:00:00:01')) dstmac = str(traffic_param['outer_l2'].get('dstmac', '00:00:00:00:00:02')) if traffic_param['outer_l2'].get('QinQ'): s_vlan = traffic_param['outer_l2']['QinQ']['S-VLAN'] c_vlan = traffic_param['outer_l2']['QinQ']['C-VLAN'] field_descriptor = self._get_field_in_stack_item( self._get_stack_item(fg_id, PROTO_ETHERNET)[0], 'etherType') self.ixnet.setMultiAttribute(field_descriptor, '-auto', 'false', '-singleValue', ETHER_TYPE_802_1ad, '-fieldValue', ETHER_TYPE_802_1ad, '-valueType', SINGLE_VALUE) self._append_procotol_to_stack( PROTO_VLAN, config_element + '/stack:"ethernet-1"') self._append_procotol_to_stack( PROTO_VLAN, config_element + '/stack:"ethernet-1"') self._update_vlan_tag(fg_id, s_vlan, S_VLAN) self._update_vlan_tag(fg_id, c_vlan, C_VLAN) self.ixnet.setMultiAttribute( config_element + '/transmissionControl', '-type', type, '-duration', duration) self.ixnet.setMultiAttribute(config_element + '/frameRate', '-rate', traffic_param['rate'], '-type', rate_unit) if len(weighted_range_pairs): self.ixnet.setMultiAttribute(config_element + '/frameSize', '-type', 'weightedPairs', '-weightedRangePairs', weighted_range_pairs) self.ixnet.commit() if dstmac: self._update_frame_mac( self._get_stack_item(fg_id, PROTO_ETHERNET)[0], 'destinationAddress', dstmac) if srcmac: self._update_frame_mac( self._get_stack_item(fg_id, PROTO_ETHERNET)[0], 'sourceAddress', srcmac)