Search in sources :

Example 1 with IP

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

Example 2 with IP

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

the class DefaultLispEncapsulatedControlTest method setup.

@Before
public void setup() {
    // Creates ecm1
    EcmBuilder builder1 = new DefaultEcmBuilder();
    IP innerIp1 = new IPv4().setSourceAddress(ECM1_SRC_IP).setDestinationAddress(ECM1_DST_IP).setProtocol(IPv4.PROTOCOL_UDP).setVersion((byte) (4 & 0xf));
    UDP innerUdp1 = new UDP().setSourcePort(1).setDestinationPort(2);
    RegisterBuilder msgBuilder = new DefaultRegisterBuilder();
    List<LispMapRecord> records1 = ImmutableList.of(getMapRecord(), getMapRecord());
    LispMapRegister innerMsg1 = msgBuilder.withIsProxyMapReply(true).withIsWantMapNotify(false).withKeyId((short) 1).withAuthKey(AUTH_KEY).withNonce(1L).withMapRecords(records1).build();
    ecm1 = builder1.isSecurity(false).innerIpHeader(innerIp1).innerUdpHeader(innerUdp1).innerLispMessage(innerMsg1).build();
    // Creates sameAsEcm1
    EcmBuilder builder2 = new DefaultEcmBuilder();
    IP innerIp2 = new IPv4().setSourceAddress(ECM1_SRC_IP).setDestinationAddress(ECM1_DST_IP).setProtocol(IPv4.PROTOCOL_UDP);
    UDP innerUdp2 = new UDP().setSourcePort(1).setDestinationPort(2);
    RegisterBuilder msgBuilder2 = new DefaultRegisterBuilder();
    List<LispMapRecord> records2 = ImmutableList.of(getMapRecord(), getMapRecord());
    LispMapRegister innerMsg2 = msgBuilder2.withIsProxyMapReply(true).withIsWantMapNotify(false).withKeyId((short) 1).withAuthKey(AUTH_KEY).withNonce(1L).withMapRecords(records2).build();
    sameAsEcm1 = builder2.isSecurity(false).innerIpHeader(innerIp2).innerUdpHeader(innerUdp2).innerLispMessage(innerMsg2).build();
    // Creates ecm2
    EcmBuilder builder3 = new DefaultEcmBuilder();
    IP innerIp3 = new IPv4().setSourceAddress(ECM2_SRC_IP).setDestinationAddress(ECM2_DST_IP).setProtocol(IPv4.PROTOCOL_UDP);
    UDP innerUdp3 = new UDP().setSourcePort(10).setDestinationPort(20);
    RegisterBuilder msgBuilder3 = new DefaultRegisterBuilder();
    List<LispMapRecord> records3 = ImmutableList.of(getMapRecord(), getMapRecord());
    LispMapRegister innerMsg3 = msgBuilder3.withIsProxyMapReply(true).withIsWantMapNotify(false).withKeyId((short) 2).withAuthKey(AUTH_KEY).withNonce(1L).withMapRecords(records3).build();
    ecm2 = builder3.isSecurity(false).innerIpHeader(innerIp3).innerUdpHeader(innerUdp3).innerLispMessage(innerMsg3).build();
}
Also used : UDP(org.onlab.packet.UDP) DefaultEcmBuilder(org.onosproject.lisp.msg.protocols.DefaultLispEncapsulatedControl.DefaultEcmBuilder) EcmBuilder(org.onosproject.lisp.msg.protocols.LispEncapsulatedControl.EcmBuilder) IP(org.onlab.packet.IP) IPv4(org.onlab.packet.IPv4) DefaultEcmBuilder(org.onosproject.lisp.msg.protocols.DefaultLispEncapsulatedControl.DefaultEcmBuilder) RegisterBuilder(org.onosproject.lisp.msg.protocols.LispMapRegister.RegisterBuilder) DefaultRegisterBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.DefaultRegisterBuilder) DefaultRegisterBuilder(org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.DefaultRegisterBuilder) Before(org.junit.Before)

Aggregations

IP (org.onlab.packet.IP)2 IPv4 (org.onlab.packet.IPv4)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 ByteBuffer (java.nio.ByteBuffer)1 Optional (java.util.Optional)1 Queue (java.util.Queue)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1 Before (org.junit.Before)1 EthType (org.onlab.packet.EthType)1 Ethernet (org.onlab.packet.Ethernet)1 IPv6 (org.onlab.packet.IPv6)1 IpAddress (org.onlab.packet.IpAddress)1 INET6 (org.onlab.packet.IpAddress.Version.INET6)1 MacAddress (org.onlab.packet.MacAddress)1 UDP (org.onlab.packet.UDP)1 VlanId (org.onlab.packet.VlanId)1 Tools (org.onlab.util.Tools)1