Example #1
0
  private void sendArpNdpProbe(
      ConnectPoint connectPoint,
      IpAddress targetIp,
      IpAddress sourceIp,
      MacAddress sourceMac,
      VlanId vlan) {
    Ethernet probePacket = null;

    if (targetIp.isIp4()) {
      // IPv4: Use ARP
      probePacket = buildArpRequest(targetIp, sourceIp, sourceMac, vlan);
    } else {
      // IPv6: Use Neighbor Discovery
      probePacket = buildNdpRequest(targetIp, sourceIp, sourceMac, vlan);
    }

    List<Instruction> instructions = new ArrayList<>();
    instructions.add(Instructions.createOutput(connectPoint.port()));

    TrafficTreatment treatment =
        DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build();

    OutboundPacket outboundPacket =
        new DefaultOutboundPacket(
            connectPoint.deviceId(), treatment, ByteBuffer.wrap(probePacket.serialize()));

    packetService.emit(outboundPacket);
  }
 @Override
 public final void setChannel(Channel channel) {
   this.channel = channel;
   final SocketAddress address = channel.getRemoteAddress();
   if (address instanceof InetSocketAddress) {
     final InetSocketAddress inetAddress = (InetSocketAddress) address;
     final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
     if (ipAddress.isIp4()) {
       channelId = ipAddress.toString() + ':' + inetAddress.getPort();
     } else {
       channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
     }
   }
 }