Search in sources :

Example 31 with IPv4

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

the class PimInterface method sendJoinPrune.

private void sendJoinPrune(McastRoute route, RouteData data, boolean join) {
    PIMJoinPrune jp = new PIMJoinPrune();
    jp.addJoinPrune(route.source().toIpPrefix(), route.group().toIpPrefix(), join);
    jp.setHoldTime(join ? (short) Math.floor(JOIN_PERIOD * HOLD_TIME_MULTIPLIER) : 0);
    jp.setUpstreamAddr(new PIMAddrUnicast(data.ipAddress.toString()));
    PIM pim = new PIM();
    pim.setPIMType(PIM.TYPE_JOIN_PRUNE_REQUEST);
    pim.setPayload(jp);
    IPv4 ipv4 = new IPv4();
    ipv4.setDestinationAddress(PIM.PIM_ADDRESS.getIp4Address().toInt());
    ipv4.setSourceAddress(getIpAddress().getIp4Address().toInt());
    ipv4.setProtocol(IPv4.PROTOCOL_PIM);
    ipv4.setTtl((byte) 1);
    ipv4.setDiffServ((byte) 0xc0);
    ipv4.setPayload(pim);
    Ethernet eth = new Ethernet();
    eth.setSourceMACAddress(onosInterface.mac());
    eth.setDestinationMACAddress(MacAddress.valueOf("01:00:5E:00:00:0d"));
    eth.setEtherType(Ethernet.TYPE_IPV4);
    eth.setPayload(ipv4);
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(onosInterface.connectPoint().port()).build();
    packetService.emit(new DefaultOutboundPacket(onosInterface.connectPoint().deviceId(), treatment, ByteBuffer.wrap(eth.serialize())));
    data.timestamp = System.currentTimeMillis();
}
Also used : PIMJoinPrune(org.onlab.packet.pim.PIMJoinPrune) PIMAddrUnicast(org.onlab.packet.pim.PIMAddrUnicast) PIM(org.onlab.packet.PIM) IPv4(org.onlab.packet.IPv4) Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 32 with IPv4

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

the class PimInterface method processJoinPrune.

/**
 * Process an incoming PIM JoinPrune message.
 *
 * @param ethPkt the Ethernet packet header.
 */
public void processJoinPrune(Ethernet ethPkt) {
    IPv4 ip = (IPv4) ethPkt.getPayload();
    checkNotNull(ip);
    PIM pim = (PIM) ip.getPayload();
    checkNotNull(pim);
    PIMJoinPrune jpHdr = (PIMJoinPrune) pim.getPayload();
    checkNotNull(jpHdr);
    /*
         * The Join/Prune messages are grouped by Group address. We'll walk each group address
         * where we will possibly have to walk a list of source address for the joins and prunes.
         */
    Collection<PIMJoinPruneGroup> jpgs = jpHdr.getJoinPrunes();
    for (PIMJoinPruneGroup jpg : jpgs) {
        IpPrefix gpfx = jpg.getGroup();
        // Walk the joins first.
        for (IpPrefix spfx : jpg.getJoins().values()) {
        // We may need
        }
        for (IpPrefix spfx : jpg.getPrunes().values()) {
        // TODO: this is where we many need to remove multi-cast state and possibly intents.
        }
    }
}
Also used : PIMJoinPrune(org.onlab.packet.pim.PIMJoinPrune) IpPrefix(org.onlab.packet.IpPrefix) PIM(org.onlab.packet.PIM) PIMJoinPruneGroup(org.onlab.packet.pim.PIMJoinPruneGroup) IPv4(org.onlab.packet.IPv4)

Example 33 with IPv4

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

the class DirectHostManager method transformAndSend.

private void transformAndSend(IP ip, short ethType, Interface egressInterface, MacAddress macAddress) {
    // Base processing for IPv4
    if (ethType == Ethernet.TYPE_IPV4) {
        IPv4 ipv4 = (IPv4) ip;
        ipv4.setTtl((byte) (ipv4.getTtl() - 1));
        ipv4.setChecksum((short) 0);
    // Base processing for IPv6.
    } else {
        IPv6 ipv6 = (IPv6) ip;
        ipv6.setHopLimit((byte) (ipv6.getHopLimit() - 1));
        ipv6.resetChecksum();
    }
    // Sends and serializes.
    Ethernet eth = new Ethernet();
    eth.setDestinationMACAddress(macAddress);
    eth.setSourceMACAddress(egressInterface.mac());
    eth.setEtherType(ethType);
    eth.setPayload(ip);
    if (!egressInterface.vlan().equals(VlanId.NONE)) {
        eth.setVlanID(egressInterface.vlan().toShort());
    }
    send(eth, egressInterface.connectPoint());
}
Also used : IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) Ethernet(org.onlab.packet.Ethernet)

Example 34 with IPv4

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

the class SimpleFabricRouting method checkVirtualGatewayIpPacket.

/**
 * handle Packet with dstIp=virtualGatewayIpAddresses.
 * returns true(handled) or false(not for virtual gateway)
 */
private boolean checkVirtualGatewayIpPacket(InboundPacket pkt, IpAddress srcIp, IpAddress dstIp) {
    // assume valid
    Ethernet ethPkt = pkt.parsed();
    MacAddress mac = simpleFabric.vMacForIp(dstIp);
    if (mac == null || !simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC())) {
        /* Destination MAC should be any of virtual gateway macs */
        return false;
    } else if (dstIp.isIp4()) {
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
            if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
                log.info("IPV4 ICMP ECHO request to virtual gateway: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
                OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmpPacket.buildIcmpReply(pkt.parsed()).serialize()));
                packetService.emit(packet);
                return true;
            }
        }
        log.warn("IPV4 packet to virtual gateway dropped: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
        return true;
    } else if (dstIp.isIp6()) {
        // TODO: not tested yet (2017-07-20)
        IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
            if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
                log.info("IPV6 ICMP6 ECHO request to virtual gateway: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
                OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmp6Packet.buildIcmp6Reply(pkt.parsed()).serialize()));
                packetService.emit(packet);
                return true;
            }
        }
        log.warn("IPV6 packet to virtual gateway dropped: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
        return true;
    }
    // unknown traffic
    return false;
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ICMP6(org.onlab.packet.ICMP6) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ICMP(org.onlab.packet.ICMP)

Example 35 with IPv4

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

the class TunnellingConnectivityManager method forward.

/**
 * Forwards a BGP packet to another connect point.
 *
 * @param context the packet context of the incoming packet
 */
private void forward(PacketContext context) {
    ConnectPoint outputPort = null;
    IPv4 ipv4 = (IPv4) context.inPacket().parsed().getPayload();
    IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
    if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
        if (bgpSpeaker.peers().contains(dstAddress)) {
            Interface intf = interfaceService.getMatchingInterface(dstAddress);
            if (intf != null) {
                outputPort = intf.connectPoint();
            }
        }
    } else {
        Set<Interface> interfaces = interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());
        if (interfaces.stream().flatMap(intf -> intf.ipAddressesList().stream()).anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
            outputPort = bgpSpeaker.connectPoint();
        }
    }
    if (outputPort != null) {
        TrafficTreatment t = DefaultTrafficTreatment.builder().setOutput(outputPort.port()).build();
        OutboundPacket o = new DefaultOutboundPacket(outputPort.deviceId(), t, context.inPacket().unparsed());
        packetService.emit(o);
    }
}
Also used : Interface(org.onosproject.net.intf.Interface) InterfaceService(org.onosproject.net.intf.InterfaceService) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) TCP(org.onlab.packet.TCP) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) TpPort(org.onlab.packet.TpPort) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Set(java.util.Set) PacketService(org.onosproject.net.packet.PacketService) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) BgpConfig(org.onosproject.routing.config.BgpConfig) IPv4(org.onlab.packet.IPv4) PacketContext(org.onosproject.net.packet.PacketContext) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Interface(org.onosproject.net.intf.Interface) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket)

Aggregations

IPv4 (org.onlab.packet.IPv4)54 Ethernet (org.onlab.packet.Ethernet)43 UDP (org.onlab.packet.UDP)24 DHCP (org.onlab.packet.DHCP)18 ICMP (org.onlab.packet.ICMP)17 IpAddress (org.onlab.packet.IpAddress)15 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 Test (org.junit.Test)12 Ip4Address (org.onlab.packet.Ip4Address)10 MacAddress (org.onlab.packet.MacAddress)10 ConnectPoint (org.onosproject.net.ConnectPoint)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 ByteBuffer (java.nio.ByteBuffer)8 Optional (java.util.Optional)8 Interface (org.onosproject.net.intf.Interface)8 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)8 DhcpOption (org.onlab.packet.dhcp.DhcpOption)7 ApplicationId (org.onosproject.core.ApplicationId)7