コード例 #1
0
  private void transformAndSend(IPv4 ipv4, Interface egressInterface, MacAddress macAddress) {

    Ethernet eth = new Ethernet();
    eth.setDestinationMACAddress(macAddress);
    eth.setSourceMACAddress(egressInterface.mac());
    eth.setEtherType(EthType.EtherType.IPV4.ethType().toShort());
    eth.setPayload(ipv4);
    if (!egressInterface.vlan().equals(VlanId.NONE)) {
      eth.setVlanID(egressInterface.vlan().toShort());
    }

    ipv4.setTtl((byte) (ipv4.getTtl() - 1));
    ipv4.setChecksum((short) 0);

    send(eth, egressInterface.connectPoint());
  }
コード例 #2
0
ファイル: IcmpHandler.java プロジェクト: santuari/onos
  /**
   * Sends an ICMP reply message.
   *
   * <p>Note: we assume that packets sending from the edge switches to the hosts have untagged VLAN.
   *
   * @param icmpRequest the original ICMP request
   * @param outport the output port where the ICMP reply should be sent to
   */
  private void sendICMPResponse(Ethernet icmpRequest, ConnectPoint outport) {
    // Note: We assume that packets arrive at the edge switches have
    // untagged VLAN.
    Ethernet icmpReplyEth = new Ethernet();

    IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload();
    IPv4 icmpReplyIpv4 = new IPv4();

    int destAddress = icmpRequestIpv4.getDestinationAddress();
    icmpReplyIpv4.setDestinationAddress(icmpRequestIpv4.getSourceAddress());
    icmpReplyIpv4.setSourceAddress(destAddress);
    icmpReplyIpv4.setTtl((byte) 64);
    icmpReplyIpv4.setChecksum((short) 0);

    ICMP icmpReply = new ICMP();
    icmpReply.setPayload(((ICMP) icmpRequestIpv4.getPayload()).getPayload());
    icmpReply.setIcmpType(ICMP.TYPE_ECHO_REPLY);
    icmpReply.setIcmpCode(ICMP.SUBTYPE_ECHO_REPLY);
    icmpReply.setChecksum((short) 0);
    icmpReplyIpv4.setPayload(icmpReply);

    icmpReplyEth.setPayload(icmpReplyIpv4);
    icmpReplyEth.setEtherType(Ethernet.TYPE_IPV4);
    icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress());
    icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress());

    Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress());
    Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress);
    int sid = config.getSegmentId(destRouterAddress);
    if (sid < 0) {
      log.warn("Cannot find the Segment ID for {}", destAddress);
      return;
    }

    sendPacketOut(outport, icmpReplyEth, sid);
  }