Search in sources :

Example 91 with Ip4Address

use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.

the class RoutingRulePopulator method manageIpPunts.

/**
 * Creates or removes forwarding objectives ( packet-requests ) to punt all IP packets, destined to the
 * router's port IP addresses, to the controller. Note that the input
 * port should not be matched on, as these packets can come from any input.
 * Furthermore, these are applied only by the master instance.
 *
 * @param deviceId the switch dpid for the router
 * @param request true to create a packet request, false to remove
 */
void manageIpPunts(DeviceId deviceId, boolean request) {
    Ip4Address routerIpv4, pairRouterIpv4 = null;
    Ip6Address routerIpv6, routerLinkLocalIpv6, pairRouterIpv6 = null;
    try {
        routerIpv4 = config.getRouterIpv4(deviceId);
        routerIpv6 = config.getRouterIpv6(deviceId);
        routerLinkLocalIpv6 = Ip6Address.valueOf(IPv6.getLinkLocalAddress(config.getDeviceMac(deviceId).toBytes()));
        if (config.isPairedEdge(deviceId)) {
            pairRouterIpv4 = config.getRouterIpv4(config.getPairDeviceId(deviceId));
            pairRouterIpv6 = config.getRouterIpv6(config.getPairDeviceId(deviceId));
        }
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting manageIpPunts.");
        return;
    }
    if (request && !srManager.shouldProgram(deviceId)) {
        log.debug("Not installing port-IP punts - not handling programming for dev:{} ", deviceId);
        return;
    }
    Set<IpAddress> allIps = new HashSet<>(config.getPortIPs(deviceId));
    allIps.add(routerIpv4);
    if (routerIpv6 != null) {
        allIps.add(routerIpv6);
        allIps.add(routerLinkLocalIpv6);
    }
    if (pairRouterIpv4 != null) {
        allIps.add(pairRouterIpv4);
    }
    if (pairRouterIpv6 != null) {
        allIps.add(pairRouterIpv6);
    }
    for (IpAddress ipaddr : allIps) {
        manageSingleIpPunts(deviceId, ipaddr, request);
    }
}
Also used : Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) IpAddress(org.onlab.packet.IpAddress) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) HashSet(java.util.HashSet)

Example 92 with Ip4Address

use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.

the class IcmpHandler method sendIcmpResponse.

/**
 * Sends an ICMP reply message.
 *
 * @param icmpRequest the original ICMP request
 * @param outport the output port where the ICMP reply should be sent to
 */
private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) {
    Ethernet icmpReplyEth = ICMP.buildIcmpReply(icmpRequest);
    IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
    IPv4 icmpReplyIpv4 = (IPv4) icmpReplyEth.getPayload();
    Ip4Address destIpAddress = Ip4Address.valueOf(icmpRequestIpv4.getSourceAddress());
    // Get the available connect points
    Set<ConnectPoint> destConnectPoints = config.getConnectPointsForASubnetHost(destIpAddress);
    // Select a router
    Ip4Address destRouterAddress = selectRouterIp4Address(destIpAddress, outport, destConnectPoints);
    // Lookup the route store for the nexthop instead.
    if (destRouterAddress == null) {
        Optional<DeviceId> deviceId = srManager.routeService.longestPrefixLookup(destIpAddress).map(srManager::nextHopLocations).flatMap(locations -> locations.stream().findFirst()).map(ConnectPoint::deviceId);
        if (deviceId.isPresent()) {
            try {
                destRouterAddress = config.getRouterIpv4(deviceId.get());
            } catch (DeviceConfigNotFoundException e) {
                log.warn("Device config for {} not found. Abort ICMP processing", deviceId);
                return;
            }
        }
    }
    int destSid = config.getIPv4SegmentId(destRouterAddress);
    if (destSid < 0) {
        log.warn("Failed to lookup SID of the switch that {} attaches to. " + "Unable to process ICMP request.", destIpAddress);
        return;
    }
    sendPacketOut(outport, icmpReplyEth, destSid, destIpAddress, icmpReplyIpv4.getTtl());
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ICMP6(org.onlab.packet.ICMP6) Arrays(java.util.Arrays) Interface(org.onosproject.net.intf.Interface) LoggerFactory(org.slf4j.LoggerFactory) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) NeighborSolicitation(org.onlab.packet.ndp.NeighborSolicitation) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) OutboundPacket(org.onosproject.net.packet.OutboundPacket) NeighbourMessageType(org.onosproject.net.neighbour.NeighbourMessageType) IpAddress(org.onlab.packet.IpAddress) NeighbourMessageContext(org.onosproject.net.neighbour.NeighbourMessageContext) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Address(org.onlab.packet.Ip6Address) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) ICMP(org.onlab.packet.ICMP) Collectors(java.util.stream.Collectors) IPv6(org.onlab.packet.IPv6) Objects(java.util.Objects) IPv4(org.onlab.packet.IPv4) MPLS(org.onlab.packet.MPLS) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DeviceId(org.onosproject.net.DeviceId) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) Ip4Address(org.onlab.packet.Ip4Address) ConnectPoint(org.onosproject.net.ConnectPoint) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 93 with Ip4Address

use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.

the class IpHandler method forwardPackets.

/**
 * Forwards IP packets in the buffer to the destination IP address.
 * It is called when the controller finds the destination MAC address
 * via ARP responses.
 *
 * @param deviceId switch device ID
 * @param destIpAddress destination IP address
 */
public void forwardPackets(DeviceId deviceId, Ip4Address destIpAddress) {
    if (ipPacketQueue.get(destIpAddress) == null) {
        return;
    }
    for (IP ipPacket : ipPacketQueue.get(destIpAddress)) {
        if (ipPacket.getVersion() == ((byte) 4)) {
            IPv4 ipv4Packet = (IPv4) ipPacket;
            Ip4Address destAddress = Ip4Address.valueOf(ipv4Packet.getDestinationAddress());
            if (config.inSameSubnet(deviceId, destAddress)) {
                ipv4Packet.setTtl((byte) (ipv4Packet.getTtl() - 1));
                ipv4Packet.setChecksum((short) 0);
                for (Host dest : srManager.hostService.getHostsByIp(destIpAddress)) {
                    Ethernet eth = new Ethernet();
                    eth.setDestinationMACAddress(dest.mac());
                    try {
                        eth.setSourceMACAddress(config.getDeviceMac(deviceId));
                    } catch (DeviceConfigNotFoundException e) {
                        log.warn(e.getMessage() + " Skipping forwardPackets for this destination.");
                        continue;
                    }
                    eth.setEtherType(Ethernet.TYPE_IPV4);
                    eth.setPayload(ipv4Packet);
                    forwardToHost(deviceId, eth, dest);
                    ipPacketQueue.get(destIpAddress).remove(ipPacket);
                }
                ipPacketQueue.get(destIpAddress).remove(ipPacket);
            }
        }
    }
}
Also used : IP(org.onlab.packet.IP) IPv4(org.onlab.packet.IPv4) Ethernet(org.onlab.packet.Ethernet) Ip4Address(org.onlab.packet.Ip4Address) Host(org.onosproject.net.Host) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 94 with Ip4Address

use of org.onlab.packet.Ip4Address in project trellis-control by opennetworkinglab.

the class ArpHandler method isArpForRouter.

private boolean isArpForRouter(NeighbourMessageContext pkt) {
    Ip4Address targetProtocolAddress = pkt.target().getIp4Address();
    Set<IpAddress> gatewayIpAddresses = null;
    try {
        if (targetProtocolAddress.equals(config.getRouterIpv4(pkt.inPort().deviceId()))) {
            return true;
        }
        gatewayIpAddresses = config.getPortIPs(pkt.inPort().deviceId());
    } catch (DeviceConfigNotFoundException e) {
        log.warn(e.getMessage() + " Aborting check for router IP in processing arp");
    }
    if (gatewayIpAddresses != null && gatewayIpAddresses.contains(targetProtocolAddress)) {
        return true;
    }
    return false;
}
Also used : Ip4Address(org.onlab.packet.Ip4Address) IpAddress(org.onlab.packet.IpAddress) DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException)

Example 95 with Ip4Address

use of org.onlab.packet.Ip4Address 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

Ip4Address (org.onlab.packet.Ip4Address)98 Test (org.junit.Test)29 Ip4Prefix (org.onlab.packet.Ip4Prefix)20 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)15 MacAddress (org.onlab.packet.MacAddress)15 ArrayList (java.util.ArrayList)14 Ip6Address (org.onlab.packet.Ip6Address)14 IpAddress (org.onlab.packet.IpAddress)13 LinkedList (java.util.LinkedList)12 Ethernet (org.onlab.packet.Ethernet)12 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)12 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)12 AsPath (org.onosproject.bgpio.types.AsPath)12 BgpHeader (org.onosproject.bgpio.types.BgpHeader)12 BgpValueType (org.onosproject.bgpio.types.BgpValueType)12 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)12 Med (org.onosproject.bgpio.types.Med)12 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)12 Origin (org.onosproject.bgpio.types.Origin)12 OriginType (org.onosproject.bgpio.types.Origin.OriginType)12