org.onlab.packet.Ethernet Java Examples

The following examples show how to use org.onlab.packet.Ethernet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DnatServiceImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void programRules(DeviceId deviceId, IpAddress dstIp,
                         MacAddress ethSrc, IpAddress ipDst,
                         SegmentationId actionVni, Objective.Operation type) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPDst(IpPrefix.valueOf(dstIp, PREFIX_LENGTH)).build();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setEthSrc(ethSrc).setIpDst(ipDst)
            .setTunnelId(Long.parseLong(actionVni.segmentationId()));
    ForwardingObjective.Builder objective = DefaultForwardingObjective
            .builder().withTreatment(treatment.build())
            .withSelector(selector).fromApp(appId).withFlag(Flag.SPECIFIC)
            .withPriority(DNAT_PRIORITY);
    if (type.equals(Objective.Operation.ADD)) {
        log.debug("RouteRules-->ADD");
        flowObjectiveService.forward(deviceId, objective.add());
    } else {
        log.debug("RouteRules-->REMOVE");
        flowObjectiveService.forward(deviceId, objective.remove());
    }
}
 
Example #2
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    NeighborSolicitation ns = new NeighborSolicitation();
    ICMP6 icmp6 = new ICMP6();
    icmp6.setPayload(ns);
    IPv6 ipv6 = new IPv6();
    ipv6.setPayload(icmp6);
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1:ff00:0000").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(BCMAC2)
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #3
Source File: IntentPushTestCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
private List<Intent> generateIntents(ConnectPoint ingress, ConnectPoint egress) {
    TrafficSelector.Builder selectorBldr = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4);
    TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();

    List<Intent> intents = Lists.newArrayList();
    for (long i = 0; i < count; i++) {
        TrafficSelector selector = selectorBldr
                .matchEthSrc(MacAddress.valueOf(i + keyOffset))
                .build();
        intents.add(PointToPointIntent.builder()
                .appId(appId())
                .key(Key.of(i + keyOffset, appId()))
                .selector(selector)
                .treatment(treatment)
                .filteredIngressPoint(new FilteredConnectPoint(ingress))
                .filteredEgressPoint(new FilteredConnectPoint(egress))
                .build());
        keysForInstall.add(Key.of(i + keyOffset, appId()));
        keysForWithdraw.add(Key.of(i + keyOffset, appId()));
    }
    return intents;
}
 
Example #4
Source File: IcmpHandlerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void testPing4RemoteGatewayLeafDown() {
    // Expected behavior
    expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF))
            .andReturn(false)
            .times(1);
    replay(segmentRoutingManager.deviceService);

    // Process
    icmpHandler.processIcmp(ETH_REQ_IPV4, CP11);

    // Verify packet-out
    Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4.getSourceMAC());
    assertNull(ethernet);

    // Verify behavior
    verify(segmentRoutingManager.deviceService);
}
 
Example #5
Source File: OpenstackRoutingSnatIcmpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setIcmpReplyRules(DeviceId deviceId, boolean install) {
    // Sends ICMP response to controller for SNATing ingress traffic
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchIPProtocol(IPv4.PROTOCOL_ICMP)
            .matchIcmpType(ICMP.TYPE_ECHO_REPLY)
            .build();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .punt()
            .build();

    osFlowRuleService.setRule(
            appId,
            deviceId,
            selector,
            treatment,
            PRIORITY_INTERNAL_ROUTING_RULE,
            GW_COMMON_TABLE,
            install);
}
 
Example #6
Source File: PimPacket.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Fill in defaults for the Ethernet, IPv4 and PIM headers, then associate each
 * of these headers as payload and parent accordingly.
 */
public void initDefaults() {
    // Prepopulate dst MACAddress and Ethernet Types. The Source MAC needs to be filled in.
    ethHeader.setDestinationMACAddress(pimDestinationMac);
    ethHeader.setEtherType(Ethernet.TYPE_IPV4);

    // Prepopulate the IP Type and Dest address. The Source IP address needs to be filled in.
    ipHeader.setDestinationAddress(PIM.PIM_ADDRESS.getIp4Address().toInt());
    ipHeader.setTtl((byte) 1);
    ipHeader.setProtocol(IPv4.PROTOCOL_PIM);

    // Establish the order between Ethernet and IP headers
    ethHeader.setPayload(ipHeader);
    ipHeader.setParent(ethHeader);

    // Prepopulate the PIM packet
    pimHeader.setPIMType(pimType);

    // Establish the order between IP and PIM headers
    ipHeader.setPayload(pimHeader);
    pimHeader.setParent(ipHeader);
}
 
Example #7
Source File: SimpleFabricRouting.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Request packet in via the PacketService.
 */
private void registerIntercepts() {
    // register default intercepts on packetService for broder routing intercepts

    packetService.requestPackets(
        DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).build(),
        PacketPriority.REACTIVE, appId);

    if (ALLOW_IPV6) {
        packetService.requestPackets(
            DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV6).build(),
            PacketPriority.REACTIVE, appId);
    }

    log.info("simple fabric routing ip packet intercepts started");
}
 
Example #8
Source File: K8sSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setLocalTunnelTagFlowRules(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_IPV4)
            .matchInPort(PortNumber.LOCAL)
            .build();

    K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
            .setTunnelId(Long.valueOf(net.segmentId()))
            .transition(JUMP_TABLE);

    k8sFlowRuleService.setRule(
            appId,
            k8sNode.intgBridge(),
            selector,
            tBuilder.build(),
            PRIORITY_TUNNEL_TAG_RULE,
            VTAG_TABLE,
            install);
}
 
Example #9
Source File: EthernetCodec.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectNode encode(Ethernet ethernet, CodecContext context) {
    checkNotNull(ethernet, "Ethernet cannot be null");

    final ObjectNode result = context.mapper().createObjectNode()
            .put("vlanId", ethernet.getVlanID())
            .put("etherType", ethernet.getEtherType())
            .put("priorityCode", ethernet.getPriorityCode())
            .put("pad", ethernet.isPad());

    if (ethernet.getDestinationMAC() != null) {
        result.put("destMac",
                   ethernet.getDestinationMAC().toString());
    }

    if (ethernet.getSourceMAC() != null) {
        result.put("srcMac",
                   ethernet.getSourceMAC().toString());
    }

    return result;
}
 
Example #10
Source File: K8sRoutingSnatHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setContainerToExtRule(K8sNode k8sNode, boolean install) {

        K8sNetwork net = k8sNetworkService.network(k8sNode.hostname());

        if (net == null) {
            return;
        }

        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
                .matchEthType(Ethernet.TYPE_IPV4)
                .matchTunnelId(Long.valueOf(net.segmentId()))
                .matchEthDst(DEFAULT_GATEWAY_MAC);

        TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
                .setOutput(k8sNode.intgToExtPatchPortNum());

        k8sFlowRuleService.setRule(
                appId,
                k8sNode.intgBridge(),
                sBuilder.build(),
                tBuilder.build(),
                PRIORITY_EXTERNAL_ROUTING_RULE,
                ROUTING_TABLE,
                install);
    }
 
Example #11
Source File: K8sNodePortHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setDefaultExtEgrRule(K8sNode k8sNode, boolean install) {
    TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder()
            .matchInPort(PortNumber.LOCAL)
            .matchEthType(Ethernet.TYPE_IPV4);

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
            .setOutput(k8sNode.extBridgePortNum());

    k8sFlowRuleService.setRule(
            appId,
            k8sNode.extBridge(),
            sBuilder.build(),
            tBuilder.build(),
            PRIORITY_NODE_PORT_INTER_RULE,
            EXT_ENTRY_TABLE,
            install);
}
 
Example #12
Source File: K8sSwitchingHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the flow rule which is for using VXLAN/GRE/GENEVE to tag the packet
 * based on the in_port number of a virtual instance.
 * Note that this rule will be inserted in vTag table.
 *
 * @param port kubernetes port object
 * @param install install flag, add the rule if true, remove it otherwise
 */
private void setTunnelTagFlowRules(K8sPort port, short ethType, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(ethType)
            .matchInPort(port.portNumber())
            .build();

    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder()
            .setTunnelId(getVni(port));

    if (ethType == Ethernet.TYPE_ARP) {
        tBuilder.transition(ARP_TABLE);
    } else if (ethType == Ethernet.TYPE_IPV4) {
        tBuilder.transition(JUMP_TABLE);
    }

    k8sFlowRuleService.setRule(
            appId,
            port.deviceId(),
            selector,
            tBuilder.build(),
            PRIORITY_TUNNEL_TAG_RULE,
            VTAG_TABLE,
            install);
}
 
Example #13
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    // Ensure packet is IPv6 Solicited RA
    InboundPacket pkt = context.inPacket();
    Ethernet ethernet = pkt.parsed();
    if ((ethernet == null) || (ethernet.getEtherType() != Ethernet.TYPE_IPV6)) {
        return;
    }
    IPv6 ipv6Packet = (IPv6) ethernet.getPayload();
    if (ipv6Packet.getNextHeader() != IPv6.PROTOCOL_ICMP6) {
        return;
    }
    ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
    if (icmp6Packet.getIcmpType() != ICMP6.ROUTER_SOLICITATION) {
        return;
    }

    // Start solicited-RA handling thread
    SolicitedRAWorkerThread sraWorkerThread = new SolicitedRAWorkerThread(pkt);
    executors.schedule(sraWorkerThread, 0, TimeUnit.SECONDS);
}
 
Example #14
Source File: K8sRoutingArpHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void setArpReplyRule(K8sNode k8sNode, boolean install) {
    TrafficSelector selector = DefaultTrafficSelector.builder()
            .matchEthType(Ethernet.TYPE_ARP)
            .matchArpOp(ARP.OP_REPLY)
            .matchArpSpa(Ip4Address.valueOf(k8sNode.extGatewayIp().toString()))
            .build();

    TrafficTreatment treatment = DefaultTrafficTreatment.builder()
            .punt()
            .build();

    k8sFlowRuleService.setRule(
            appId,
            k8sNode.extBridge(),
            selector,
            treatment,
            PRIORITY_ARP_REPLY_RULE,
            EXT_ENTRY_TABLE,
            install
    );
}
 
Example #15
Source File: SimpleFabricRouting.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowRule generateInterceptFlowRule(boolean isDstLocalSubnet, DeviceId deviceId, IpPrefix prefix) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (prefix.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        if (prefix.prefixLength() > 0) {
            selector.matchIPDst(prefix);
        }
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        if (prefix.prefixLength() > 0) {
            selector.matchIPv6Dst(prefix);
        }
    }
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withPriority(reactivePriority(false, isDstLocalSubnet, prefix.prefixLength()))
            .withSelector(selector.build())
            .withTreatment(DefaultTrafficTreatment.builder().punt().build())
            .fromApp(appId)
            .makePermanent()
            .forTable(0).build();
    return rule;
}
 
Example #16
Source File: NSPacketClassifier.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public boolean match(PacketContext packet) {

    Ethernet eth = packet.inPacket().parsed();

    if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
        IPv6 ipv6Packet = (IPv6) eth.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6 = (ICMP6) ipv6Packet.getPayload();
            if (icmp6.getIcmpType() == ICMP6.NEIGHBOR_SOLICITATION) {
                return true;
            }
        }
    }
    return false;
}
 
Example #17
Source File: HostLocationProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public InboundPacket inPacket() {
    IPv6 ipv6 = new IPv6();
    ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
    ipv6.setSourceAddress(IP2);
    Ethernet eth = new Ethernet();
    eth.setEtherType(Ethernet.TYPE_IPV6)
            .setVlanID(VLAN.toShort())
            .setSourceMACAddress(MAC2.toBytes())
            .setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01"))
            .setPayload(ipv6);
    ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
                                                 portNumber(INPORT));
    return new DefaultInboundPacket(receivedFrom, eth,
                                    ByteBuffer.wrap(eth.serialize()));
}
 
Example #18
Source File: DirectHostManager.java    From onos with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #19
Source File: OpenstackTroubleshootManager.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an east-west ICMP packet with given source and destination IP/MAC.
 *
 * @param srcPort   source instance port
 * @param dstPort   destination instance port
 * @param icmpId    ICMP identifier
 * @param icmpSeq   ICMP sequence number
 * @return an ethernet frame which contains ICMP payload
 */
private Ethernet constructEastWestIcmpPacket(InstancePort srcPort,
                                             InstancePort dstPort,
                                             short icmpId, short icmpSeq) {
    boolean isRemote = true;

    if (srcPort.deviceId().equals(dstPort.deviceId()) &&
            osNetworkService.gatewayIp(srcPort.portId())
                    .equals(osNetworkService.gatewayIp(dstPort.portId()))) {
        isRemote = false;
    }

    // if the source and destination VMs are located in different OVS,
    // we will assign fake gateway MAC as the destination MAC
    MacAddress dstMac = isRemote ? DEFAULT_GATEWAY_MAC : dstPort.macAddress();

    return constructIcmpPacket(srcPort.ipAddress(), dstPort.ipAddress(),
                                srcPort.macAddress(), dstMac, icmpId, icmpSeq);
}
 
Example #20
Source File: SegmentRoutingNeighbourHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Utility to send a ND reply using the supplied information.
 *
 * @param pkt the request
 * @param targetMac the target mac
 * @param hostService the host service
 * @param isRouter true if this reply is sent on behalf of a router
 */
protected void sendResponse(NeighbourMessageContext pkt, MacAddress targetMac, HostService hostService,
                            boolean isRouter) {
    // if this is false, check if host exists in the store
    if (!respondToUnknownHosts()) {
        short vlanId = pkt.packet().getQinQVID();
        HostId dstId = HostId.hostId(pkt.srcMac(), vlanId == Ethernet.VLAN_UNTAGGED
                ? pkt.vlan() : VlanId.vlanId(vlanId));
        Host dst = hostService.getHost(dstId);
        if (dst == null) {
            log.warn("Cannot send {} response to host {} - does not exist in the store",
                     pkt.protocol(), dstId);
            return;
        }
    }
    pkt.setIsRouter(isRouter);
    pkt.reply(targetMac);
}
 
Example #21
Source File: Dhcp6HandlerUtil.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Dhcp6Option getInterfaceIdIdOption(PacketContext context, Ethernet clientPacket) {
    String inPortString = "-" + context.inPacket().receivedFrom().toString() + ":";
    Dhcp6Option interfaceId = new Dhcp6Option();
    interfaceId.setCode(DHCP6.OptionCode.INTERFACE_ID.value());
    byte[] clientSoureMacBytes = clientPacket.getSourceMACAddress();
    byte[] inPortStringBytes = inPortString.getBytes();
    byte[] vlanIdBytes = new byte[2];
    vlanIdBytes[0] = (byte) ((clientPacket.getVlanID() >> 8) & 0xff);
    vlanIdBytes[1] = (byte) (clientPacket.getVlanID() & 0xff);
    byte[] interfaceIdBytes = new byte[clientSoureMacBytes.length +
            inPortStringBytes.length + vlanIdBytes.length];
    log.debug("Length: interfaceIdBytes  {} clientSoureMacBytes {} inPortStringBytes {} vlan {}",
            interfaceIdBytes.length, clientSoureMacBytes.length, inPortStringBytes.length,
            vlanIdBytes.length);

    System.arraycopy(clientSoureMacBytes, 0, interfaceIdBytes, 0, clientSoureMacBytes.length);
    System.arraycopy(inPortStringBytes, 0, interfaceIdBytes, clientSoureMacBytes.length,
            inPortStringBytes.length);
    System.arraycopy(vlanIdBytes, 0, interfaceIdBytes,
            clientSoureMacBytes.length + inPortStringBytes.length,
            vlanIdBytes.length);
    interfaceId.setData(interfaceIdBytes);
    interfaceId.setLength((short) interfaceIdBytes.length);
    log.debug("interfaceId write srcMac {} portString {}, vlanId {}",
            HexString.toHexString(clientSoureMacBytes, ":"), inPortString, vlanIdBytes);
    return interfaceId;
}
 
Example #22
Source File: IcmpHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #23
Source File: DefaultOpenFlowPacketContext.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void build(Ethernet ethFrame, OFPort outPort) {
    if (isBuilt.getAndSet(true)) {
        return;
    }
    OFAction act = buildOutput(outPort.getPortNumber());
    pktout = createOFPacketOut(ethFrame.serialize(), act, pktin.getXid());
}
 
Example #24
Source File: RouterAdvertisementManager.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {

    // TODO : Validate Router Solicitation

    // Pause already running unsolicited RA threads in received connect point
    ConnectPoint connectPoint = packet.receivedFrom();
    List<InterfaceIpAddress> addresses = deactivateRouterAdvertisement(connectPoint);

    /* Multicast RA(ie. Unsolicited RA) TX time is not preciously tracked so to make sure that
     * Unicast RA(ie. Router Solicitation Response) is TXed before Mulicast RA
     * logic adapted here is disable Mulicast RA, TX Unicast RA and then restore Multicast RA.
     */
    log.trace("Processing Router Solicitations from {}", connectPoint);
    try {
        Ethernet ethernet = packet.parsed();
        IPv6 ipv6 = (IPv6) ethernet.getPayload();
        RAWorkerThread worker = new RAWorkerThread(connectPoint,
                addresses, raThreadDelay, ethernet.getSourceMAC(), ipv6.getSourceAddress());
        // TODO : Estimate TX time as in RFC 4861, Section 6.2.6 and schedule TX based on it
        CompletableFuture<Void> sraHandlerFuture = CompletableFuture.runAsync(worker, executors);
        sraHandlerFuture.get();
    } catch (Exception e) {
        log.error("Failed to respond to router solicitation. {}", e);
    } finally {
        activateRouterAdvertisement(connectPoint, addresses);
        log.trace("Restored Unsolicited Router Advertisements on {}", connectPoint);
    }
}
 
Example #25
Source File: DefaultHostProbingProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Send the probe packet on given port.
 *
 * @param probe the probe packet
 * @param connectPoint the port we want to probe
 */
private void sendLocationProbe(Ethernet probe, ConnectPoint connectPoint) {
    log.debug("Sending probe for host {} on location {} with probeMac {}",
            probe.getDestinationMAC(), connectPoint, probe.getSourceMAC());
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();
    OutboundPacket outboundPacket = new DefaultOutboundPacket(connectPoint.deviceId(),
            treatment, ByteBuffer.wrap(probe.serialize()));
    packetService.emit(outboundPacket);
}
 
Example #26
Source File: OpenstackSwitchingArpHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void process(PacketContext context) {
    if (context.isHandled()) {
        return;
    }

    Ethernet ethPacket = context.inPacket().parsed();
    if (ethPacket == null || ethPacket.getEtherType() != Ethernet.TYPE_ARP) {
        return;
    }

    eventExecutor.execute(() -> processPacketIn(context, ethPacket));
}
 
Example #27
Source File: VbngManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * PointToPointIntent Generator.
 * <p>
 * The intent will match the destination IP address in packet, rewrite the
 * destination IP address, and rewrite the destination MAC address.
 * </p>
 *
 * @param dstIpAddress the destination IP address in packet to match
 * @param newDstIpAddress the new destination IP address to set
 * @param dstMacAddress the destination MAC address to set
 * @param dstConnectPoint the egress point
 * @param srcConnectPoint the ingress point
 * @return a PointToPointIntent
 */
private PointToPointIntent dstMatchIntentGenerator(
                                            IpAddress dstIpAddress,
                                            IpAddress newDstIpAddress,
                                            MacAddress dstMacAddress,
                                            ConnectPoint dstConnectPoint,
                                            ConnectPoint srcConnectPoint) {
    checkNotNull(dstIpAddress);
    checkNotNull(newDstIpAddress);
    checkNotNull(dstMacAddress);
    checkNotNull(dstConnectPoint);
    checkNotNull(srcConnectPoint);

    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchIPDst(IpPrefix.valueOf(dstIpAddress,
                                         IpPrefix.MAX_INET_MASK_LENGTH));

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.setEthDst(dstMacAddress);
    treatment.setIpDst(newDstIpAddress);

    Key key = Key.of(newDstIpAddress.toString() + "MatchDst", appId);
    PointToPointIntent intent = PointToPointIntent.builder()
            .appId(appId)
            .key(key)
            .selector(selector.build())
            .treatment(treatment.build())
            .filteredEgressPoint(new FilteredConnectPoint(dstConnectPoint))
            .filteredIngressPoint(new FilteredConnectPoint(srcConnectPoint))
            .build();
    log.info("Generated a PointToPointIntent for traffic to local host "
            + ": {}", intent);

    return intent;
}
 
Example #28
Source File: OpenstackRoutingHandler.java    From onos with Apache License 2.0 5 votes vote down vote up
private void setReactiveGatewayIcmpRule(IpAddress gatewayIp, DeviceId deviceId, boolean install) {

        TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
        int icmpRulePriority;

        if (getStatefulSnatFlag()) {
            sBuilder.matchEthType(Ethernet.TYPE_IPV4)
                    .matchIPProtocol(IPv4.PROTOCOL_ICMP)
                    .matchIcmpType(ICMP.TYPE_ECHO_REQUEST);
            icmpRulePriority = PRIORITY_ICMP_REQUEST_RULE;
        } else {
            sBuilder.matchEthType(Ethernet.TYPE_IPV4)
                    .matchIPProtocol(IPv4.PROTOCOL_ICMP)
                    .matchIPDst(gatewayIp.getIp4Address().toIpPrefix());
            icmpRulePriority = PRIORITY_ICMP_RULE;
        }

        TrafficTreatment treatment = DefaultTrafficTreatment.builder()
                .punt()
                .build();

        osFlowRuleService.setRule(
                appId,
                deviceId,
                sBuilder.build(),
                treatment,
                icmpRulePriority,
                Constants.GW_COMMON_TABLE,
                install);
    }
 
Example #29
Source File: OpenFlowPacketProviderTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private OutboundPacket outPacket(DeviceId d, TrafficTreatment t, Ethernet e,
                                 PortNumber inPort) {
    ByteBuffer buf = null;
    if (e != null) {
        buf = ByteBuffer.wrap(e.serialize());
    }
    return new DefaultOutboundPacket(d, t, buf, inPort);
}
 
Example #30
Source File: FilteringObjectiveTranslator.java    From onos with Apache License 2.0 5 votes vote down vote up
private Collection<FlowRule> ipFwdClassifierRules(
        PortNumber inPort, MacAddress dstMac, FilteringObjective obj)
        throws FabricPipelinerException {
    final Collection<FlowRule> flowRules = Lists.newArrayList();
    flowRules.add(fwdClassifierRule(
            inPort, Ethernet.TYPE_IPV4, dstMac, null,
            fwdClassifierTreatment(FWD_IPV4_ROUTING), obj));
    flowRules.add(fwdClassifierRule(
            inPort, Ethernet.TYPE_IPV6, dstMac, null,
            fwdClassifierTreatment(FWD_IPV6_ROUTING), obj));
    return flowRules;
}