コード例 #1
0
ファイル: HostMonitor.java プロジェクト: rvhub/onos
  private Ethernet buildArpRequest(
      IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) {

    ARP arp = new ARP();
    arp.setHardwareType(ARP.HW_TYPE_ETHERNET)
        .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
        .setProtocolType(ARP.PROTO_TYPE_IP)
        .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH)
        .setOpCode(ARP.OP_REQUEST);

    arp.setSenderHardwareAddress(sourceMac.toBytes())
        .setSenderProtocolAddress(sourceIp.toOctets())
        .setTargetHardwareAddress(ZERO_MAC_ADDRESS)
        .setTargetProtocolAddress(targetIp.toOctets());

    Ethernet ethernet = new Ethernet();
    ethernet
        .setEtherType(Ethernet.TYPE_ARP)
        .setDestinationMACAddress(MacAddress.BROADCAST)
        .setSourceMACAddress(sourceMac)
        .setPayload(arp);

    if (!vlan.equals(VlanId.NONE)) {
      ethernet.setVlanID(vlan.toShort());
    }

    ethernet.setPad(true);

    return ethernet;
  }
コード例 #2
0
ファイル: ArpHandler.java プロジェクト: gunine/onos
  /**
   * Sends an APR request for the target IP address to all ports except in-port.
   *
   * @param deviceId Switch device ID
   * @param targetAddress target IP address for ARP
   * @param inPort in-port
   */
  public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) {
    byte[] senderMacAddress;
    byte[] senderIpAddress;

    try {
      senderMacAddress = config.getDeviceMac(deviceId).toBytes();
      senderIpAddress = config.getRouterIp(deviceId).toOctets();
    } catch (DeviceConfigNotFoundException e) {
      log.warn(e.getMessage() + " Aborting sendArpRequest.");
      return;
    }

    ARP arpRequest = new ARP();
    arpRequest
        .setHardwareType(ARP.HW_TYPE_ETHERNET)
        .setProtocolType(ARP.PROTO_TYPE_IP)
        .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
        .setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH)
        .setOpCode(ARP.OP_REQUEST)
        .setSenderHardwareAddress(senderMacAddress)
        .setTargetHardwareAddress(MacAddress.ZERO.toBytes())
        .setSenderProtocolAddress(senderIpAddress)
        .setTargetProtocolAddress(targetAddress.toOctets());

    Ethernet eth = new Ethernet();
    eth.setDestinationMACAddress(MacAddress.BROADCAST.toBytes())
        .setSourceMACAddress(senderMacAddress)
        .setEtherType(Ethernet.TYPE_ARP)
        .setPayload(arpRequest);

    removeVlanAndFlood(eth, inPort);
  }
コード例 #3
0
ファイル: HostMonitor.java プロジェクト: rvhub/onos
  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;
  }
コード例 #4
0
  @Override
  public byte[] getBytes() throws HeaderException {
    try {
      byte[] data = new byte[LENGTH];

      System.arraycopy(exporterIPv4Address.toOctets(), 0, data, 0, 4);
      System.arraycopy(exporterIPv6Address.toOctets(), 0, data, 4, 16);
      System.arraycopy(Longs.toByteArray(flowStartMilliseconds), 0, data, 20, 8);
      System.arraycopy(Longs.toByteArray(flowEndMilliseconds), 0, data, 28, 8);
      System.arraycopy(Longs.toByteArray(octetDeltaCount), 0, data, 36, 8);
      System.arraycopy(Longs.toByteArray(packetDeltaCount), 0, data, 44, 8);
      System.arraycopy(Ints.toByteArray(ingressInterface), 0, data, 52, 4);
      System.arraycopy(Ints.toByteArray(egressInterface), 0, data, 56, 4);
      System.arraycopy(sourceMacAddress.toBytes(), 0, data, 60, 6);
      System.arraycopy(destinationMacAddress.toBytes(), 0, data, 66, 6);
      System.arraycopy(Shorts.toByteArray(ethernetType), 0, data, 72, 2);
      System.arraycopy(Shorts.toByteArray(vlanId), 0, data, 74, 2);

      return data;
    } catch (Exception e) {
      throw new HeaderException("Error while generating the bytes: " + e.getMessage());
    }
  }