blob: 6a04f8328924cfe5b5ed81b5b5adfb62123b891c [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.
39 */
40 static String fingerprintMac(ClusterMetadata cm) {
41 if (cm == null) {
42 return DEFAULT_MAC;
43 }
44
45 HashFunction hf = Hashing.murmur3_32();
46 HashCode hc = hf.newHasher().putObject(cm, ClusterMetadata.HASH_FUNNEL).hash();
47 int unqf = hc.asInt();
48
49 StringBuilder sb = new StringBuilder();
50 sb.append("02:eb");
51 for (int i = 0; i < 4; i++) {
52 byte b = (byte) (unqf >> i * 8);
53 sb.append(String.format(":%02X", b));
54 }
55 return sb.toString();
56 }
57}