Search in sources :

Example 16 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class OpenFlowPacketProviderTest method emit.

@Test
public void emit() {
    MacAddress mac1 = MacAddress.of("00:00:00:11:00:01");
    MacAddress mac2 = MacAddress.of("00:00:00:22:00:02");
    ARP arp = new ARP();
    arp.setSenderProtocolAddress(ANY).setSenderHardwareAddress(mac1.getBytes()).setTargetHardwareAddress(mac2.getBytes()).setTargetProtocolAddress(ANY).setHardwareType((short) 0).setProtocolType((short) 0).setHardwareAddressLength((byte) 6).setProtocolAddressLength((byte) 4).setOpCode((byte) 0);
    Ethernet eth = new Ethernet();
    eth.setVlanID(VLANID).setEtherType(Ethernet.TYPE_ARP).setSourceMACAddress("00:00:00:11:00:01").setDestinationMACAddress("00:00:00:22:00:02").setPayload(arp);
    // the should-be working setup.
    OutboundPacket passPkt = outPacket(DID, TR, eth);
    sw.setRole(RoleState.MASTER);
    provider.emit(passPkt);
    assertEquals("invalid switch", sw, controller.current);
    assertEquals("message not sent", PLIST.size(), sw.sent.size());
    sw.sent.clear();
    // Send with different IN_PORT
    OutboundPacket inPortPkt = outPacket(DID, TR_ALL, eth, IN_PORT);
    sw.setRole(RoleState.MASTER);
    provider.emit(inPortPkt);
    assertEquals("invalid switch", sw, controller.current);
    assertEquals("message not sent", PLIST_ALL.size(), sw.sent.size());
    OFMessage ofMessage = sw.sent.get(0);
    assertEquals("Wrong OF message type", OFType.PACKET_OUT, ofMessage.getType());
    OFPacketOut packetOut = (OFPacketOut) ofMessage;
    assertEquals("Wrong in port", OFPort.of(IN_PORT_PN), packetOut.getInPort());
    assertEquals("Unexpected number of actions", 1, packetOut.getActions().size());
    OFAction ofAction = packetOut.getActions().get(0);
    assertEquals("Packet out action should be type output", OFActionType.OUTPUT, ofAction.getType());
    OFActionOutput ofActionOutput = (OFActionOutput) ofAction;
    assertEquals("Output should be ALL", OFPort.ALL, ofActionOutput.getPort());
    sw.sent.clear();
    // wrong Role
    // sw.setRole(RoleState.SLAVE);
    // provider.emit(passPkt);
    // assertEquals("invalid switch", sw, controller.current);
    // assertEquals("message sent incorrectly", 0, sw.sent.size());
    // sw.setRole(RoleState.MASTER);
    // missing switch
    OutboundPacket swFailPkt = outPacket(DID_MISSING, TR, eth);
    provider.emit(swFailPkt);
    assertNull("invalid switch", controller.current);
    assertEquals("message sent incorrectly", 0, sw.sent.size());
// to missing port
// OutboundPacket portFailPkt = outPacket(DID, TR_MISSING, eth);
// provider.emit(portFailPkt);
// assertEquals("extra message sent", 1, sw.sent.size());
}
Also used : OFActionOutput(org.projectfloodlight.openflow.protocol.action.OFActionOutput) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) Ethernet(org.onlab.packet.Ethernet) OFAction(org.projectfloodlight.openflow.protocol.action.OFAction) MacAddress(org.projectfloodlight.openflow.types.MacAddress) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut) ARP(org.onlab.packet.ARP) Test(org.junit.Test)

Example 17 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class K8sSwitchingArpHandler method processArpReply.

private void processArpReply(PacketContext context, Ethernet ethPacket) {
    ARP arpPacket = (ARP) ethPacket.getPayload();
    IpAddress srcIp = IpAddress.valueOf(INET, arpPacket.getSenderProtocolAddress());
    MacAddress srcMac = MacAddress.valueOf(arpPacket.getSenderHardwareAddress());
    IpAddress dstIp = IpAddress.valueOf(INET, arpPacket.getTargetProtocolAddress());
    if (dstIp.equals(IpAddress.valueOf(NODE_FAKE_IP_STR))) {
        // mutable MAP scenario is not considered for now
        if (!extHostMacStore.containsKey(srcIp)) {
            extHostMacStore.put(srcIp, srcMac);
        }
        K8sNode k8sNode = k8sNodeService.nodes().stream().filter(n -> n.nodeIp().equals(srcIp)).findAny().orElse(null);
        if (k8sNode == null) {
            return;
        } else {
            if (k8sNode.nodeInfo().nodeMac() != null) {
                return;
            }
        }
        // we update node MAC address which will be referred in node port scenario
        K8sNodeInfo nodeInfo = new K8sNodeInfo(k8sNode.nodeIp(), srcMac);
        K8sNode updatedNode = k8sNode.updateNodeInfo(nodeInfo);
        k8sNodeService.updateNode(updatedNode);
    }
}
Also used : K8sNodeInfo(org.onosproject.k8snode.api.K8sNodeInfo) K8sNode(org.onosproject.k8snode.api.K8sNode) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) ARP(org.onlab.packet.ARP)

Example 18 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class NeighbourTestUtils method createArpRequest.

/**
 * Creates an ARP request for the given target IP.
 *
 * @param targetIp IP address
 * @return ARP request packet
 */
public static Ethernet createArpRequest(IpAddress targetIp) {
    Ethernet eth = new Ethernet();
    eth.setDestinationMACAddress(MAC1);
    eth.setSourceMACAddress(MAC2);
    eth.setEtherType(Ethernet.TYPE_ARP);
    ARP arp = new ARP();
    arp.setOpCode(ARP.OP_REPLY);
    arp.setProtocolType(ARP.PROTO_TYPE_IP);
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET);
    arp.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH);
    arp.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH);
    arp.setSenderHardwareAddress(MAC2.toBytes());
    arp.setTargetHardwareAddress(MacAddress.ZERO.toBytes());
    arp.setTargetProtocolAddress(targetIp.toOctets());
    arp.setSenderProtocolAddress(IP2.toOctets());
    eth.setPayload(arp);
    return eth;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP)

Example 19 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class OpenstackRoutingArpHandler method processArpPacket.

private void processArpPacket(PacketContext context, Ethernet ethernet) {
    ARP arp = (ARP) ethernet.getPayload();
    if (arp.getOpCode() == ARP.OP_REQUEST && ARP_PROXY_MODE.equals(getArpMode())) {
        if (log.isTraceEnabled()) {
            log.trace("ARP request received from {} for {}", Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(), Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString());
        }
        IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress());
        MacAddress targetMac = null;
        NetFloatingIP floatingIP = osRouterAdminService.floatingIps().stream().filter(ip -> ip.getFloatingIpAddress().equals(targetIp.toString())).findAny().orElse(null);
        // In case target ip is for associated floating ip, sets target mac to vm's.
        if (floatingIP != null && floatingIP.getPortId() != null) {
            InstancePort instPort = instancePortService.instancePort(floatingIP.getPortId());
            if (instPort == null) {
                log.trace("Unknown target ARP request for {}, ignore it", targetIp);
                return;
            } else {
                targetMac = instPort.macAddress();
            }
            OpenstackNode gw = getGwByInstancePort(osNodeService.completeNodes(GATEWAY), instPort);
            if (gw == null) {
                return;
            }
            // if the ARP packet_in received from non-relevant GWs, we simply ignore it
            if (!Objects.equals(gw.intgBridge(), context.inPacket().receivedFrom().deviceId())) {
                return;
            }
        }
        if (isExternalGatewaySourceIp(targetIp)) {
            targetMac = Constants.DEFAULT_GATEWAY_MAC;
        }
        if (targetMac == null) {
            log.trace("Unknown target ARP request for {}, ignore it", targetIp);
            return;
        }
        Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), targetMac, ethernet);
        TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(context.inPacket().receivedFrom().port()).build();
        packetService.emit(new DefaultOutboundPacket(context.inPacket().receivedFrom().deviceId(), treatment, ByteBuffer.wrap(ethReply.serialize())));
        context.block();
    }
    if (arp.getOpCode() == ARP.OP_REPLY) {
        ConnectPoint cp = context.inPacket().receivedFrom();
        PortNumber receivedPortNum = cp.port();
        IpAddress spa = Ip4Address.valueOf(arp.getSenderProtocolAddress());
        MacAddress sha = MacAddress.valueOf(arp.getSenderHardwareAddress());
        log.debug("ARP reply ip: {}, mac: {}", spa, sha);
        try {
            Set<String> extRouterIps = osNetworkService.externalPeerRouters().stream().map(r -> r.ipAddress().toString()).collect(Collectors.toSet());
            // if SPA is NOT contained in existing external router IP set, we ignore it
            if (!extRouterIps.contains(spa.toString())) {
                return;
            }
            OpenstackNode node = osNodeService.node(cp.deviceId());
            if (node == null) {
                return;
            }
            // we only handles the ARP-Reply message received by gateway node
            if (node.type() != GATEWAY) {
                return;
            }
            if (receivedPortNum.equals(node.uplinkPortNum())) {
                osNetworkAdminService.updateExternalPeerRouterMac(spa, sha);
            }
        } catch (Exception e) {
            log.error("Exception occurred because of {}", e);
        }
    }
}
Also used : OpenstackNetworkingUtil.getGwByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByInstancePort) OpenstackNetworkingUtil.processGarpPacketForFloatingIp(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.processGarpPacketForFloatingIp) CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) OpenstackRouterAdminService(org.onosproject.openstacknetworking.api.OpenstackRouterAdminService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ARP(org.onlab.packet.ARP) Constants(org.onosproject.openstacknetworking.api.Constants) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) OpenstackNetworkingUtil.externalGatewayIp(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalGatewayIp) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) InstancePortAdminService(org.onosproject.openstacknetworking.api.InstancePortAdminService) OpenstackNodeListener(org.onosproject.openstacknode.api.OpenstackNodeListener) ApplicationId(org.onosproject.core.ApplicationId) RulePopulatorUtil.buildMoveEthSrcToDstExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveEthSrcToDstExtension) RulePopulatorUtil.buildMoveArpShaToThaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpShaToThaExtension) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) ExternalPeerRouter(org.onosproject.openstacknetworking.api.ExternalPeerRouter) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) ImmutableSet(com.google.common.collect.ImmutableSet) Ip4Address(org.onlab.packet.Ip4Address) Device(org.onosproject.net.Device) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) ARP_PROXY_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_PROXY_MODE) Deactivate(org.osgi.service.component.annotations.Deactivate) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) InboundPacket(org.onosproject.net.packet.InboundPacket) NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) OpenstackNetworkingUtil.getGwByComputeDevId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByComputeDevId) PacketContext(org.onosproject.net.packet.PacketContext) ClusterService(org.onosproject.cluster.ClusterService) ARP_MODE_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE_DEFAULT) OpenstackNetworkingUtil.floatingIpByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.floatingIpByInstancePort) DeviceId(org.onosproject.net.DeviceId) GATEWAY(org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) GATEWAY_MAC_DEFAULT(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.GATEWAY_MAC_DEFAULT) ComponentContext(org.osgi.service.component.ComponentContext) RulePopulatorUtil.buildMoveArpSpaToTpaExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildMoveArpSpaToTpaExtension) OpenstackRouterEvent(org.onosproject.openstacknetworking.api.OpenstackRouterEvent) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) GW_COMMON_TABLE(org.onosproject.openstacknetworking.api.Constants.GW_COMMON_TABLE) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OpenstackNetworkAdminService(org.onosproject.openstacknetworking.api.OpenstackNetworkAdminService) Objects.requireNonNull(java.util.Objects.requireNonNull) Router(org.openstack4j.model.network.Router) IP(org.openstack4j.model.network.IP) Activate(org.osgi.service.component.annotations.Activate) OpenstackNetworkingUtil.externalPeerRouterForNetwork(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterForNetwork) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ARP_MODE(org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) Port(org.openstack4j.model.network.Port) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) PRIORITY_ARP_GATEWAY_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_GATEWAY_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackRouterListener(org.onosproject.openstacknetworking.api.OpenstackRouterListener) OpenstackNodeEvent(org.onosproject.openstacknode.api.OpenstackNodeEvent) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) PRIORITY_ARP_CONTROL_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ARP_CONTROL_RULE) LeadershipService(org.onosproject.cluster.LeadershipService) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) OpenstackNetworkingUtil.getGwByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getGwByInstancePort) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) OpenstackNetworkingUtil.floatingIpByInstancePort(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.floatingIpByInstancePort) NetFloatingIP(org.openstack4j.model.network.NetFloatingIP) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber) ARP(org.onlab.packet.ARP)

Example 20 with ARP

use of org.onlab.packet.ARP in project onos by opennetworkinglab.

the class OpenstackSwitchingArpHandler method processPacketIn.

/**
 * Processes ARP request packets.
 * It checks if the target IP is owned by a known host first and then ask to
 * OpenStack if it's not. This ARP proxy does not support overlapping IP.
 *
 * @param context   packet context
 * @param ethPacket ethernet packet
 */
private void processPacketIn(PacketContext context, Ethernet ethPacket) {
    // if the ARP mode is configured as broadcast mode, we simply ignore ARP packet_in
    if (ARP_BROADCAST_MODE.equals(getArpMode())) {
        return;
    }
    ARP arpPacket = (ARP) ethPacket.getPayload();
    if (arpPacket.getOpCode() != ARP.OP_REQUEST) {
        return;
    }
    InstancePort srcInstPort = instancePortService.instancePort(ethPacket.getSourceMAC());
    if (srcInstPort == null) {
        log.trace("Failed to find source instance port(MAC:{})", ethPacket.getSourceMAC());
        return;
    }
    IpAddress targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
    MacAddress replyMac = isGatewayIp(targetIp) ? MacAddress.valueOf(gatewayMac) : getMacFromHostOpenstack(targetIp, srcInstPort.networkId());
    if (replyMac == MacAddress.NONE) {
        log.trace("Failed to find MAC address for {}", targetIp);
        return;
    }
    Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), replyMac, ethPacket);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(context.inPacket().receivedFrom().port()).build();
    packetService.emit(new DefaultOutboundPacket(context.inPacket().receivedFrom().deviceId(), treatment, ByteBuffer.wrap(ethReply.serialize())));
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Ethernet(org.onlab.packet.Ethernet) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ARP(org.onlab.packet.ARP)

Aggregations

ARP (org.onlab.packet.ARP)20 Ethernet (org.onlab.packet.Ethernet)15 IpAddress (org.onlab.packet.IpAddress)9 MacAddress (org.onlab.packet.MacAddress)7 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)7 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)6 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)6 ByteBuffer (java.nio.ByteBuffer)5 Set (java.util.Set)5 Ip4Address (org.onlab.packet.Ip4Address)5 ConnectPoint (org.onosproject.net.ConnectPoint)5 DeviceId (org.onosproject.net.DeviceId)5 PacketService (org.onosproject.net.packet.PacketService)5 Logger (org.slf4j.Logger)5 Objects (java.util.Objects)4 ExecutorService (java.util.concurrent.ExecutorService)4 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 VlanId (org.onlab.packet.VlanId)4