def _create_pong_packet(self, buf): pkt = ryu.lib.packet.packet.Packet(buf) ether = pkt.get_protocol(ryu.lib.packet.ethernet.ethernet) ip = pkt.get_protocol(self.ip_class) icmp = pkt.get_protocol(self.icmp_class) src_mac, src_ip = apps.get_port_mac_and_ip(self.permit_port) self.assertEqual(ether.src, src_mac) self.assertEqual(ether.dst, self.port3.port.get_logical_port().mac) self.assertEqual(netaddr.IPAddress(ip.src), src_ip) self.assertEqual(netaddr.IPAddress(ip.dst), self.port3.port.get_logical_port().ip) ether.src, ether.dst = ether.dst, ether.src ip.src, ip.dst = ip.dst, ip.src if self.ethertype == n_const.IPv4: icmp.type = self.icmp_echo_reply else: icmp.type_ = self.icmp_echo_reply icmp.csum = 0 result = ryu.lib.packet.packet.Packet() result.add_protocol(ether) result.add_protocol(ip) result.add_protocol(icmp) result.serialize() return result.data
def _create_ping_packet(self, src_port, dst_port): src_mac, src_ip = apps.get_port_mac_and_ip(src_port) ethernet = ryu.lib.packet.ethernet.ethernet( src=str(src_mac), dst=str(dst_port.port.get_logical_port().mac), ethertype=self.ethtype, ) dst_ip = dst_port.port.get_logical_port().ip ip = self._create_packet_protocol(src_ip, dst_ip) icmp_id = int(time.mktime(time.gmtime())) & 0xffff icmp_seq = 0 icmp = self.icmp_class( type_=self.icmp_echo_request, data=self.icmp_echo_class(id_=icmp_id, seq=icmp_seq, data=self._create_random_string()) ) result = ryu.lib.packet.packet.Packet() result.add_protocol(ethernet) result.add_protocol(ip) result.add_protocol(icmp) result.serialize() return result, icmp
def setUp(self): super(TestAllowedAddressPairsDetectActive, self).setUp() if not self.check_app_loaded("active_port_detection"): self.skipTest("ActivePortDetectionApp is not enabled") self.topology = None self.policy = None self.allowed_address_pair_ip_address = None self.allowed_address_pair_mac_address = None try: self.topology = self.store(app_testing_objects.Topology( self.neutron, self.nb_api)) subnet = self.topology.create_subnet(cidr='192.168.98.0/24') self.subnet = subnet port = subnet.create_port() self.port = port time.sleep(const.DEFAULT_RESOURCE_READY_TIMEOUT) port.update({'allowed_address_pairs': [{ 'ip_address': '192.168.98.100'}]}) time.sleep(const.DEFAULT_RESOURCE_READY_TIMEOUT) port_lport = port.port.get_logical_port() self.assertIsNotNone(port_lport) self.allowed_address_pair_mac_address, \ self.allowed_address_pair_ip_address = \ apps.get_port_mac_and_ip(port, True) # Create policy to reply arp request sent from controller self.policy = self.store( app_testing_objects.Policy( initial_actions=[], port_policies=self._create_policy_to_reply_arp_request(), unknown_port_action=app_testing_objects.IgnoreAction() ) ) except Exception: if self.topology: self.topology.close() raise
def _create_ping_using_allowed_address_pair(self, buf): mac, ip = apps.get_port_mac_and_ip(self.port1, True) result, icmp = self._create_ping_request(ip, mac, self.port2) self._ping_using_allowed_address_pair = icmp return result.data