Java Code Examples for java.util.Enumeration#hashCode()

The following examples show how to use java.util.Enumeration#hashCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LinkDiscoveryManager.java    From floodlight_with_topoguard with Apache License 2.0 4 votes vote down vote up
@LogMessageDoc(level="WARN",
        message="Could not get list of interfaces of local machine to " +
                 "encode in TLV: {detail-msg}",
        explanation="Outgoing LLDP packets encode a unique hash to " +
                 "identify the local machine. The list of network " +
                 "interfaces is used as input and the controller failed " +
                 "to query this list",
        recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG)
protected void setControllerTLV() {
    // Setting the controllerTLVValue based on current nano time,
    // controller's IP address, and the network interface object hash
    // the corresponding IP address.

    final int prime = 7867;

    byte[] controllerTLVValue = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; // 8
                                                                       // byte
                                                                       // value.
    ByteBuffer bb = ByteBuffer.allocate(10);

    long result = System.nanoTime();
    try{
        // Use some data specific to the machine this controller is
        // running on. In this case: the list of network interfaces
        Enumeration<NetworkInterface> ifaces =
                NetworkInterface.getNetworkInterfaces();
        if (ifaces != null) {
            result = result * prime + ifaces.hashCode();
        }
    } catch (SocketException e) {
        log.warn("Could not get list of interfaces of local machine to " +
                 "encode in TLV: {}", e.toString());
    }
    // set the first 4 bits to 0.
    result = result & (0x0fffffffffffffffL);

    bb.putLong(result);

    bb.rewind();
    bb.get(controllerTLVValue, 0, 8);

    this.controllerTLV = new LLDPTLV().setType((byte) 0x0c)
                                      .setLength((short) controllerTLVValue.length)
                                      .setValue(controllerTLVValue);
}