diff options
author | Dan Klein <danklei@cisco.com> | 2015-09-24 02:35:34 +0300 |
---|---|---|
committer | Dan Klein <danklei@cisco.com> | 2015-09-24 02:35:34 +0300 |
commit | 46d15e627e46af8816c061ad33301a8e6a7aab95 (patch) | |
tree | 76b0fe27c8762eca7bd28bad8c38e161a5ba98a4 /scripts/automation/trex_control_plane/client_utils | |
parent | ed46f126c90da83929625a89b5438a11f0e75401 (diff) |
cosmetics...
Diffstat (limited to 'scripts/automation/trex_control_plane/client_utils')
-rw-r--r-- | scripts/automation/trex_control_plane/client_utils/packet_builder.py | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder.py b/scripts/automation/trex_control_plane/client_utils/packet_builder.py index 9adf7b1d..b7c456cd 100644 --- a/scripts/automation/trex_control_plane/client_utils/packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder.py @@ -260,19 +260,18 @@ class CTRexPktBuilder(object): start_val = CTRexPktBuilder._decode_ip_addr(ip_start, ip_type) end_val = CTRexPktBuilder._decode_ip_addr(ip_end, ip_type) # All validations are done, start adding VM instructions - flow_var_name = "{layer}__{field}".format(layer = ip_layer_name, field = ip_field) + flow_var_name = "{layer}__{field}".format(layer=ip_layer_name, field=ip_field) hdr_offset, field_abs_offset = self._calc_offset(ip_layer_name, ip_field) - self.vm.add_flow_man_inst(flow_var_name, size = ip_addr_size, operation = operation, - init_value = init_val, - min_value = start_val, - max_value = end_val) + self.vm.add_flow_man_inst(flow_var_name, size=ip_addr_size, operation=operation, + init_value=init_val, + min_value=start_val, + max_value=end_val) self.vm.add_write_flow_inst(flow_var_name, field_abs_offset) self.vm.set_vm_var_field(flow_var_name, "add_value", add_value) self.vm.set_vm_var_field(flow_var_name, "is_is_big_endian", is_big_endian) - if (ip_field == "ipv4" and add_checksum_inst): + if ip_field == "ipv4" and add_checksum_inst: self.vm.add_fix_checksum_inst(self._pkt_by_hdr.get(ip_layer_name), hdr_offset) - def set_vm_eth_range(self, eth_layer_name, eth_field, mac_init, mac_start, mac_end, add_value, operation, is_big_endian=False): @@ -284,27 +283,27 @@ class CTRexPktBuilder(object): start_val = CTRexPktBuilder._decode_mac_addr(mac_start) end_val = CTRexPktBuilder._decode_mac_addr(mac_end) # All validations are done, start adding VM instructions - flow_var_name = "{layer}__{field}".format(layer = eth_layer_name, field = eth_field) + flow_var_name = "{layer}__{field}".format(layer=eth_layer_name, field=eth_field) hdr_offset, field_abs_offset = self._calc_offset(eth_layer_name, eth_field) - self.vm.add_flow_man_inst(flow_var_name, size = 8, operation = operation, - init_value = init_val, - min_value = start_val, - max_value = end_val) + self.vm.add_flow_man_inst(flow_var_name, size=8, operation=operation, + init_value=init_val, + min_value=start_val, + max_value=end_val) self.vm.add_write_flow_inst(flow_var_name, field_abs_offset) self.vm.set_vm_var_field(flow_var_name, "add_value", add_value) self.vm.set_vm_var_field(flow_var_name, "is_is_big_endian", is_big_endian) def set_vm_custom_range(self, layer_name, hdr_field, init_val, start_val, end_val, add_val, val_size, - operation, is_big_endian=False, range_name = ""): + operation, is_big_endian=False, range_name=""): self._verify_layer_prop(layer_name=layer_name, field_name=hdr_field) if not range_name: - range_name = "{layer}__{field}".format(layer = layer_name, field = hdr_field) + range_name = "{layer}__{field}".format(layer=layer_name, field=hdr_field) hdr_offset, field_abs_offset = self._calc_offset(layer_name, hdr_field) - self.vm.add_flow_man_inst(range_name, size = val_size, operation = operation, - init_value = init_val, - min_value = start_val, - max_value = end_val) + self.vm.add_flow_man_inst(range_name, size=val_size, operation=operation, + init_value=init_val, + min_value=start_val, + max_value=end_val) self.vm.add_write_flow_inst(range_name, field_abs_offset) self.vm.set_vm_var_field(range_name, "add_value", add_val) self.vm.set_vm_var_field(range_name, "is_is_big_endian", is_big_endian) @@ -406,7 +405,6 @@ class CTRexPktBuilder(object): def _calc_offset(self, layer_name, hdr_field): pkt_header = self._pkt_by_hdr.get(layer_name) hdr_offset = len(self._packet) - len(pkt_header) - print hdr_offset inner_hdr_offsets = [] for field in pkt_header.__hdr__: if field[0] == hdr_field: @@ -415,7 +413,7 @@ class CTRexPktBuilder(object): inner_hdr_offsets.append(struct.calcsize(field[1])) return hdr_offset, hdr_offset + sum(inner_hdr_offsets) - def _verify_layer_prop(self, layer_name, layer_type = None, field_name=None): + def _verify_layer_prop(self, layer_name, layer_type=None, field_name=None): if layer_name not in self._pkt_by_hdr: raise CTRexPktBuilder.PacketLayerError(layer_name) pkt_layer = self._pkt_by_hdr.get(layer_name) @@ -423,15 +421,13 @@ class CTRexPktBuilder(object): # check for layer type if not isinstance(pkt_layer, layer_type): raise CTRexPktBuilder.PacketLayerTypeError(layer_name, type(pkt_layer), layer_type) - if field_name: + if field_name and not hasattr(pkt_layer, field_name): # check if field exists on certain header - if not hasattr(pkt_layer, field_name): - raise CTRexPktBuilder.PacketLayerError(layer_name, "The specified field '{0}' does not exists on " \ - "given packet layer ('{1}')". - format(field_name, layer_name)) + raise CTRexPktBuilder.PacketLayerError(layer_name, "The specified field '{0}' does not exists on " + "given packet layer ('{1}')".format(field_name, + layer_name)) return - @staticmethod def _decode_mac_addr(mac_addr): """ |