示例#1
0
 @Override
 public InboundPacket inPacket() {
   IPv4 ipv4 = new IPv4();
   ipv4.setDestinationAddress("10.0.0.1");
   ipv4.setSourceAddress(IP_ADDRESS.toString());
   Ethernet eth = new Ethernet();
   eth.setEtherType(Ethernet.TYPE_IPV4)
       .setVlanID(VLAN.toShort())
       .setSourceMACAddress(MAC)
       .setDestinationMACAddress(MacAddress.valueOf("00:00:00:00:00:01"))
       .setPayload(ipv4);
   ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId), portNumber(INPORT));
   return new DefaultInboundPacket(receivedFrom, eth, ByteBuffer.wrap(eth.serialize()));
 }
示例#2
0
  /**
   * 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);
  }