Ejemplo n.º 1
0
 @Override
 public InboundPacket inPacket() {
   RouterAdvertisement ns = new RouterAdvertisement();
   ICMP6 icmp6 = new ICMP6();
   icmp6.setPayload(ns);
   IPv6 ipv6 = new IPv6();
   ipv6.setPayload(icmp6);
   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()));
 }
Ejemplo n.º 2
0
  private Ethernet buildNdpRequest(
      IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {

    // Create the Ethernet packet
    Ethernet ethernet = new Ethernet();
    ethernet
        .setEtherType(Ethernet.TYPE_IPV6)
        .setDestinationMACAddress(MacAddress.BROADCAST)
        .setSourceMACAddress(sourceMac);
    if (!vlan.equals(VlanId.NONE)) {
      ethernet.setVlanID(vlan.toShort());
    }

    //
    // Create the IPv6 packet
    //
    // TODO: The destination IP address should be the
    // solicited-node multicast address
    IPv6 ipv6 = new IPv6();
    ipv6.setSourceAddress(sourceIp.toOctets());
    ipv6.setDestinationAddress(targetIp.toOctets());
    ipv6.setHopLimit((byte) 255);

    // Create the ICMPv6 packet
    ICMP6 icmp6 = new ICMP6();
    icmp6.setIcmpType(ICMP6.NEIGHBOR_SOLICITATION);
    icmp6.setIcmpCode((byte) 0);

    // Create the Neighbor Solication packet
    NeighborSolicitation ns = new NeighborSolicitation();
    ns.setTargetAddress(targetIp.toOctets());
    ns.addOption(NeighborDiscoveryOptions.TYPE_SOURCE_LL_ADDRESS, sourceMac.toBytes());

    icmp6.setPayload(ns);
    ipv6.setPayload(icmp6);
    ethernet.setPayload(ipv6);

    return ethernet;
  }