blob: 3b633ac553f4e232c0688062dbe362b5a5a59c3e [file] [log] [blame]
Ayaka Koshibe48229222016-05-16 18:04:26 -07001/*
2 * Copyright 2014-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.link;
17
18import com.google.common.hash.HashFunction;
19import com.google.common.hash.HashCode;
20import com.google.common.hash.Hashing;
21
22import org.onosproject.cluster.ClusterMetadata;
23
24/**
25 * Abstraction for an entity that provides information about infrastructure
26 * links that are discovered or verified using probe messages.
27 */
28public interface ProbedLinkProvider extends LinkProvider {
29
30 static final String DEFAULT_MAC = "DE:AD:BE:EF:BA:11";
31
32 static String defaultMac() {
33 return DEFAULT_MAC;
34 }
35
36 /**
37 * Build a stringified MAC address using the ClusterMetadata hash for uniqueness.
38 * Form of MAC is "02:eb" followed by four bytes of clusterMetadata hash.
Ray Milkeybb23e0b2016-08-02 17:00:21 -070039 *
40 * @param cm cluster metadata
41 * @return stringified mac address
Ayaka Koshibe48229222016-05-16 18:04:26 -070042 */
43 static String fingerprintMac(ClusterMetadata cm) {
44 if (cm == null) {
45 return DEFAULT_MAC;
46 }
47
48 HashFunction hf = Hashing.murmur3_32();
49 HashCode hc = hf.newHasher().putObject(cm, ClusterMetadata.HASH_FUNNEL).hash();
50 int unqf = hc.asInt();
51
52 StringBuilder sb = new StringBuilder();
53 sb.append("02:eb");
54 for (int i = 0; i < 4; i++) {
55 byte b = (byte) (unqf >> i * 8);
56 sb.append(String.format(":%02X", b));
57 }
58 return sb.toString();
59 }
60}