コード例 #1
0
ファイル: IcmpHandler.java プロジェクト: santuari/onos
  private void sendPacketOut(ConnectPoint outport, Ethernet payload, int sid) {

    IPv4 ipPacket = (IPv4) payload.getPayload();
    Ip4Address destIpAddress = Ip4Address.valueOf(ipPacket.getDestinationAddress());

    if (sid == -1
        || config.getSegmentId(payload.getDestinationMAC()) == sid
        || config.inSameSubnet(outport.deviceId(), destIpAddress)) {
      TrafficTreatment treatment =
          DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
      OutboundPacket packet =
          new DefaultOutboundPacket(
              outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
      srManager.packetService.emit(packet);
    } else {
      log.info("Send a MPLS packet as a ICMP response");
      TrafficTreatment treatment =
          DefaultTrafficTreatment.builder().setOutput(outport.port()).build();

      payload.setEtherType(Ethernet.MPLS_UNICAST);
      MPLS mplsPkt = new MPLS();
      mplsPkt.setLabel(sid);
      mplsPkt.setTtl(((IPv4) payload.getPayload()).getTtl());
      mplsPkt.setPayload(payload.getPayload());
      payload.setPayload(mplsPkt);

      OutboundPacket packet =
          new DefaultOutboundPacket(
              outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));

      srManager.packetService.emit(packet);
    }
  }
コード例 #2
0
ファイル: IcmpHandler.java プロジェクト: santuari/onos
  /**
   * Process incoming ICMP packet. If it is an ICMP request to router or known host, then sends an
   * ICMP response. If it is an ICMP packet to known host and forward the packet to the host. If it
   * is an ICMP packet to unknown host in a subnet, then sends an ARP request to the subnet.
   *
   * @param pkt inbound packet
   */
  public void processPacketIn(InboundPacket pkt) {

    Ethernet ethernet = pkt.parsed();
    IPv4 ipv4 = (IPv4) ethernet.getPayload();

    ConnectPoint connectPoint = pkt.receivedFrom();
    DeviceId deviceId = connectPoint.deviceId();
    Ip4Address destinationAddress = Ip4Address.valueOf(ipv4.getDestinationAddress());
    Set<Ip4Address> gatewayIpAddresses = config.getPortIPs(deviceId);
    Ip4Address routerIp;
    try {
      routerIp = config.getRouterIp(deviceId);
    } catch (DeviceConfigNotFoundException e) {
      log.warn(e.getMessage() + " Aborting processPacketIn.");
      return;
    }
    IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
    Ip4Address routerIpAddress = routerIpPrefix.getIp4Prefix().address();

    // ICMP to the router IP or gateway IP
    if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST
        && (destinationAddress.equals(routerIpAddress)
            || gatewayIpAddresses.contains(destinationAddress))) {
      sendICMPResponse(ethernet, connectPoint);

      // ICMP for any known host
    } else if (!srManager.hostService.getHostsByIp(destinationAddress).isEmpty()) {
      // TODO: known host packet should not be coming to controller - resend flows?
      srManager.ipHandler.forwardPackets(deviceId, destinationAddress);

      // ICMP for an unknown host in the subnet of the router
    } else if (config.inSameSubnet(deviceId, destinationAddress)) {
      srManager.arpHandler.sendArpRequest(deviceId, destinationAddress, connectPoint);

      // ICMP for an unknown host
    } else {
      log.debug("ICMP request for unknown host {} ", destinationAddress);
      // Do nothing
    }
  }