Search in sources :

Example 26 with Ethernet

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

the class IcmpHandlerTest method testPing4GatewayPair.

// Ping to a dh gateway
@Test
public void testPing4GatewayPair() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF1)).andReturn(true).times(1);
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF2)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_GATEWAY_PAIR, CP2011);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_GATEWAY_PAIR.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4_GATEWAY_PAIR.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV41.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 27 with Ethernet

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

the class IcmpHandlerTest method testPing4MyGateway.

// Ping to our gateway
@Test
public void testPing4MyGateway() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
    replay(segmentRoutingManager.deviceService);
    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4_MY, CP12);
    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_MY.getSourceMAC());
    assertNotNull(ethernet);
    assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_MY.getDestinationMAC()));
    assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_MY.getSourceMAC()));
    assertTrue(ethernet.getPayload() instanceof IPv4);
    IPv4 ip = (IPv4) ethernet.getPayload();
    assertThat(ip.getSourceAddress(), is(DST_IPV4.toInt()));
    assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt()));
    assertTrue(ip.getPayload() instanceof ICMP);
    ICMP icmp = (ICMP) ip.getPayload();
    assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
    assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
Also used : Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ICMP(org.onlab.packet.ICMP) Test(org.junit.Test)

Example 28 with Ethernet

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

the class HostMonitor method buildArpRequest.

private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {
    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET).setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH).setProtocolType(ARP.PROTO_TYPE_IP).setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH).setOpCode(ARP.OP_REQUEST);
    arp.setSenderHardwareAddress(sourceMac.toBytes()).setSenderProtocolAddress(sourceIp.toOctets()).setTargetHardwareAddress(ZERO_MAC_ADDRESS).setTargetProtocolAddress(targetIp.toOctets());
    Ethernet ethernet = new Ethernet();
    ethernet.setEtherType(Ethernet.TYPE_ARP).setDestinationMACAddress(MacAddress.BROADCAST).setSourceMACAddress(sourceMac).setPayload(arp);
    if (!vlan.equals(VlanId.NONE)) {
        ethernet.setVlanID(vlan.toShort());
    }
    ethernet.setPad(true);
    return ethernet;
}
Also used : Ethernet(org.onlab.packet.Ethernet) ARP(org.onlab.packet.ARP)

Example 29 with Ethernet

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

the class ReactiveForwarding method installRule.

// Install a rule forwarding the packet to the specified port.
private void installRule(PacketContext context, PortNumber portNumber, ReactiveForwardMetrics macMetrics) {
    // 
    // We don't support (yet) buffer IDs in the Flow Service so
    // packet out first.
    // 
    Ethernet inPkt = context.inPacket().parsed();
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    // If PacketOutOnly or ARP packet than forward directly to output port
    if (packetOutOnly || inPkt.getEtherType() == Ethernet.TYPE_ARP) {
        packetOut(context, portNumber, macMetrics);
        return;
    }
    // 
    if (matchDstMacOnly) {
        selectorBuilder.matchEthDst(inPkt.getDestinationMAC());
    } else {
        selectorBuilder.matchInPort(context.inPacket().receivedFrom().port()).matchEthSrc(inPkt.getSourceMAC()).matchEthDst(inPkt.getDestinationMAC());
        // If configured Match Vlan ID
        if (matchVlanId && inPkt.getVlanID() != Ethernet.VLAN_UNTAGGED) {
            selectorBuilder.matchVlanId(VlanId.vlanId(inPkt.getVlanID()));
        }
        // 
        if (matchIpv4Address && inPkt.getEtherType() == Ethernet.TYPE_IPV4) {
            IPv4 ipv4Packet = (IPv4) inPkt.getPayload();
            byte ipv4Protocol = ipv4Packet.getProtocol();
            Ip4Prefix matchIp4SrcPrefix = Ip4Prefix.valueOf(ipv4Packet.getSourceAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            Ip4Prefix matchIp4DstPrefix = Ip4Prefix.valueOf(ipv4Packet.getDestinationAddress(), Ip4Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(matchIp4SrcPrefix).matchIPDst(matchIp4DstPrefix);
            if (matchIpv4Dscp) {
                byte dscp = ipv4Packet.getDscp();
                byte ecn = ipv4Packet.getEcn();
                selectorBuilder.matchIPDscp(dscp).matchIPEcn(ecn);
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv4Protocol == IPv4.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv4Protocol == IPv4.PROTOCOL_ICMP) {
                ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv4Protocol).matchIcmpType(icmpPacket.getIcmpType()).matchIcmpCode(icmpPacket.getIcmpCode());
            }
        }
        // 
        if (matchIpv6Address && inPkt.getEtherType() == Ethernet.TYPE_IPV6) {
            IPv6 ipv6Packet = (IPv6) inPkt.getPayload();
            byte ipv6NextHeader = ipv6Packet.getNextHeader();
            Ip6Prefix matchIp6SrcPrefix = Ip6Prefix.valueOf(ipv6Packet.getSourceAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            Ip6Prefix matchIp6DstPrefix = Ip6Prefix.valueOf(ipv6Packet.getDestinationAddress(), Ip6Prefix.MAX_MASK_LENGTH);
            selectorBuilder.matchEthType(Ethernet.TYPE_IPV6).matchIPv6Src(matchIp6SrcPrefix).matchIPv6Dst(matchIp6DstPrefix);
            if (matchIpv6FlowLabel) {
                selectorBuilder.matchIPv6FlowLabel(ipv6Packet.getFlowLabel());
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_TCP) {
                TCP tcpPacket = (TCP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchTcpSrc(TpPort.tpPort(tcpPacket.getSourcePort())).matchTcpDst(TpPort.tpPort(tcpPacket.getDestinationPort()));
            }
            if (matchTcpUdpPorts && ipv6NextHeader == IPv6.PROTOCOL_UDP) {
                UDP udpPacket = (UDP) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchUdpSrc(TpPort.tpPort(udpPacket.getSourcePort())).matchUdpDst(TpPort.tpPort(udpPacket.getDestinationPort()));
            }
            if (matchIcmpFields && ipv6NextHeader == IPv6.PROTOCOL_ICMP6) {
                ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
                selectorBuilder.matchIPProtocol(ipv6NextHeader).matchIcmpv6Type(icmp6Packet.getIcmpType()).matchIcmpv6Code(icmp6Packet.getIcmpCode());
            }
        }
    }
    TrafficTreatment treatment;
    if (inheritFlowTreatment) {
        treatment = context.treatmentBuilder().setOutput(portNumber).build();
    } else {
        treatment = DefaultTrafficTreatment.builder().setOutput(portNumber).build();
    }
    ForwardingObjective forwardingObjective = DefaultForwardingObjective.builder().withSelector(selectorBuilder.build()).withTreatment(treatment).withPriority(flowPriority).withFlag(ForwardingObjective.Flag.VERSATILE).fromApp(appId).makeTemporary(flowTimeout).add();
    flowObjectiveService.forward(context.inPacket().receivedFrom().deviceId(), forwardingObjective);
    forwardPacket(macMetrics);
    // 
    if (packetOutOfppTable) {
        packetOut(context, PortNumber.TABLE, macMetrics);
    } else {
        packetOut(context, portNumber, macMetrics);
    }
}
Also used : TCP(org.onlab.packet.TCP) UDP(org.onlab.packet.UDP) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Ip6Prefix(org.onlab.packet.Ip6Prefix) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Ip4Prefix(org.onlab.packet.Ip4Prefix) ICMP6(org.onlab.packet.ICMP6) ICMP(org.onlab.packet.ICMP)

Example 30 with Ethernet

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

the class DirectHostManager method handle.

private boolean handle(Ethernet eth) {
    checkNotNull(eth);
    // skip them.
    if (!enabled || (eth.getEtherType() != Ethernet.TYPE_IPV6 && eth.getEtherType() != Ethernet.TYPE_IPV4)) {
        return false;
    }
    // According to the type we set the destIp.
    IpAddress dstIp;
    if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
        IPv4 ip = (IPv4) eth.getPayload();
        dstIp = IpAddress.valueOf(ip.getDestinationAddress());
    } else {
        IPv6 ip = (IPv6) eth.getPayload();
        dstIp = IpAddress.valueOf(INET6, ip.getDestinationAddress());
    }
    // Looking for a candidate output port.
    Interface egressInterface = interfaceService.getMatchingInterface(dstIp);
    if (egressInterface == null) {
        log.info("No egress interface found for {}", dstIp);
        return false;
    }
    // Looking for the destination mac.
    Optional<Host> host = hostService.getHostsByIp(dstIp).stream().filter(h -> h.location().equals(egressInterface.connectPoint())).filter(h -> h.vlan().equals(egressInterface.vlan())).findAny();
    // and we queue the packets waiting for a destination.
    if (host.isPresent()) {
        transformAndSend((IP) eth.getPayload(), eth.getEtherType(), egressInterface, host.get().mac());
    } else {
        hostService.startMonitoringIp(dstIp);
        ipPacketCache.asMap().compute(dstIp, (ip, queue) -> {
            if (queue == null) {
                queue = new ConcurrentLinkedQueue<>();
            }
            queue.add((IP) eth.getPayload());
            return queue;
        });
    }
    return true;
}
Also used : ENABLED(org.onosproject.routing.impl.OsgiPropertyConstants.ENABLED) Tools(org.onlab.util.Tools) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) CoreService(org.onosproject.core.CoreService) ComponentContext(org.osgi.service.component.ComponentContext) LoggerFactory(org.slf4j.LoggerFactory) INET6(org.onlab.packet.IpAddress.Version.INET6) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ApplicationId(org.onosproject.core.ApplicationId) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) ENABLED_DEFAULT(org.onosproject.routing.impl.OsgiPropertyConstants.ENABLED_DEFAULT) VlanId(org.onlab.packet.VlanId) PacketProcessor(org.onosproject.net.packet.PacketProcessor) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PacketService(org.onosproject.net.packet.PacketService) IPv6(org.onlab.packet.IPv6) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) TimeUnit(java.util.concurrent.TimeUnit) EthType(org.onlab.packet.EthType) IPv4(org.onlab.packet.IPv4) IP(org.onlab.packet.IP) PacketContext(org.onosproject.net.packet.PacketContext) Modified(org.osgi.service.component.annotations.Modified) Optional(java.util.Optional) MacAddress(org.onlab.packet.MacAddress) CacheBuilder(com.google.common.cache.CacheBuilder) PacketPriority(org.onosproject.net.packet.PacketPriority) Queue(java.util.Queue) Cache(com.google.common.cache.Cache) Reference(org.osgi.service.component.annotations.Reference) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) IpAddress(org.onlab.packet.IpAddress) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface)

Aggregations

Ethernet (org.onlab.packet.Ethernet)187 Test (org.junit.Test)91 ConnectPoint (org.onosproject.net.ConnectPoint)46 IPv4 (org.onlab.packet.IPv4)42 IPv6 (org.onlab.packet.IPv6)41 UDP (org.onlab.packet.UDP)38 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)33 MacAddress (org.onlab.packet.MacAddress)30 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)30 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)29 IpAddress (org.onlab.packet.IpAddress)28 OutboundPacket (org.onosproject.net.packet.OutboundPacket)26 DeviceId (org.onosproject.net.DeviceId)25 ByteBuffer (java.nio.ByteBuffer)24 DHCP (org.onlab.packet.DHCP)24 DHCP6 (org.onlab.packet.DHCP6)24 Interface (org.onosproject.net.intf.Interface)22 DeserializationException (org.onlab.packet.DeserializationException)20 ICMP6 (org.onlab.packet.ICMP6)20 InboundPacket (org.onosproject.net.packet.InboundPacket)20