Best Python code snippet using lisa_python
xdpdump.py
Source:xdpdump.py
...173 sed = self.node.tools[Sed]174 # replace hard code mac and ip addresses in code, the changes will be175 # reset after built.176 forwarder_mac = self._convert_mac_to_c_style(forwarder_nic.mac_addr)177 forwarder_ip = self._convert_ip_to_c_style(forwarder_nic.ip_addr)178 receiver_mac = self._convert_mac_to_c_style(receiver_nic.mac_addr)179 receiver_ip = self._convert_ip_to_c_style(receiver_nic.ip_addr)180 sed.substitute(181 regexp=r"unsigned char newethsrc \[\] = "182 "{ 0x00, 0x22, 0x48, 0x4c, 0xc4, 0x4d };",183 replacement=r"unsigned char newethsrc \[\] = {" + forwarder_mac + "};",184 file=f"{self._code_path}/xdpdump_kern.c",185 )186 sed.substitute(187 regexp=r"unsigned char newethdest \[\] = "188 "{ 0x00, 0x22, 0x48, 0x4c, 0xc0, 0xfd };",189 replacement=r"unsigned char newethdest \[\] = {" + receiver_mac + "};",190 file=f"{self._code_path}/xdpdump_kern.c",191 )192 sed.substitute(193 regexp=r"__u8 newsrc \[\] = { 10, 0, 1, 5 };",194 replacement=r"__u8 newsrc \[\] = {" + forwarder_ip + "};",195 file=f"{self._code_path}/xdpdump_kern.c",196 )197 sed.substitute(198 regexp=r"__u8 newdest \[\] = { 10, 0, 1, 4 };",199 replacement=r"__u8 newdest \[\] = {" + receiver_ip + "};",200 file=f"{self._code_path}/xdpdump_kern.c",201 )202 self.make_by_build_type(build_type=BuildType.TX_FWD)203 def _convert_mac_to_c_style(self, mac: str) -> str:204 """205 convert 00:22:48:7a:ed:28 to 0x00, 0x22, 0x48, 0x7a, 0xed, 0x28206 """207 bytes_list = [f"0x{x}" for x in mac.split(":")]208 return ", ".join(bytes_list)209 def _convert_ip_to_c_style(self, ip: str) -> str:210 """211 convert 10.0.0.1 to 10, 0, 0, 1212 """213 return ", ".join(ip.split("."))214 def _disable_lro(self, nic_name: str) -> None:215 ethtool = self.node.tools[Ethtool]216 gro_lro_settings = self._get_gro_lro_settings(nic_name)217 if gro_lro_settings.lro_setting is False:218 return219 # disable LRO (RSC), because XDP program cannot run with it. Restore220 # it after test completed.221 ethtool.change_device_gro_lro_settings(222 nic_name,223 gro_setting=gro_lro_settings.gro_setting,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!