Пример #1
0
  /**
   * Sends an ARP or Neighbor Discovery Protocol request for the given IP address.
   *
   * @param targetIp IP address to send the request for
   */
  private void sendArpNdpRequest(IpAddress targetIp) {
    Interface intf = interfaceService.getMatchingInterface(targetIp);

    if (intf == null) {
      return;
    }

    for (InterfaceIpAddress ia : intf.ipAddresses()) {
      if (ia.subnetAddress().contains(targetIp)) {
        sendArpNdpProbe(intf.connectPoint(), targetIp, ia.ipAddress(), intf.mac(), intf.vlan());
      }
    }
  }
Пример #2
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());
  }