Search in sources :

Example 21 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 22 with ARP

use of org.onlab.packet.ARP in project aaa by opencord.

the class PortBasedRadiusCommunicator method handleArpPacketFromServer.

/**
 * Handles ARP packets from RADIUS server.
 *
 * @param context Context for the packet
 */
private void handleArpPacketFromServer(PacketContext context) {
    // Extract the original Ethernet frame from the packet information
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return;
    }
    ARP arpPacket = (ARP) ethPkt.getPayload();
    Ip4Address targetAddress = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
    String serialNo = ipToSnMap.get(targetAddress);
    if (serialNo == null) {
        log.info("No mapping found for ARP reply, target address {}", targetAddress);
        return;
    }
    if (subsService == null) {
        log.warn(SADIS_NOT_RUNNING);
        return;
    }
    MacAddress senderMac = subsService.get(serialNo).hardwareIdentifier();
    if (senderMac == null) {
        log.warn("ARP resolution, MAC address not found for SN {}", serialNo);
        return;
    }
    ARP arpReply = (ARP) arpPacket.clone();
    arpReply.setOpCode(ARP.OP_REPLY);
    arpReply.setTargetProtocolAddress(arpPacket.getSenderProtocolAddress());
    arpReply.setTargetHardwareAddress(arpPacket.getSenderHardwareAddress());
    arpReply.setSenderProtocolAddress(arpPacket.getTargetProtocolAddress());
    arpReply.setSenderHardwareAddress(senderMac.toBytes());
    log.debug("AAA Manager: Query for ARP of IP : {}", arpPacket.getTargetProtocolAddress());
    // Ethernet Frame.
    Ethernet ethReply = new Ethernet();
    ethReply.setSourceMACAddress(senderMac);
    ethReply.setDestinationMACAddress(ethPkt.getSourceMAC());
    ethReply.setEtherType(Ethernet.TYPE_ARP);
    ethReply.setVlanID(radiusVlanID);
    ethReply.setPriorityCode(ethPkt.getPriorityCode());
    ethReply.setPayload(arpReply);
    sendFromRadiusServerPort(ethReply);
}
Also used : InboundPacket(org.onosproject.net.packet.InboundPacket) Ethernet(org.onlab.packet.Ethernet) Ip4Address(org.onlab.packet.Ip4Address) MacAddress(org.onlab.packet.MacAddress) ARP(org.onlab.packet.ARP)

Aggregations

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