blob: 57758b3c447f830a8ecd71c1cb0ee532a940bd9d [file] [log] [blame]
Andrea Campanellae4084402017-12-15 15:27:31 +01001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16
17package org.onosproject.t3.impl;
18
19import com.google.common.collect.ImmutableMap;
Andrea Campanella4c6170a2018-01-17 16:34:51 +010020import org.onlab.packet.MacAddress;
Andrea Campanellae4084402017-12-15 15:27:31 +010021
22import java.util.Map;
23
24/**
25 * Utility class for the troubleshooting tool.
26 */
27final class TroubleshootUtils {
28
29 private TroubleshootUtils() {
30 //Banning construction
31 }
32
33 /**
34 * Map defining if a specific driver is for a HW switch.
35 */
36 //Done with builder() instead of of() for clarity
37 static Map<String, Boolean> hardwareOfdpaMap = ImmutableMap.<String, Boolean>builder()
38 .put("ofdpa", true)
39 .put("ofdpa3", true)
40 .put("qmx-ofdpa3", true)
41 .put("as7712-32x-premium", true)
42 .put("as5912-54x-premium", true)
43 .put("as5916-54x-premium", true)
44 .put("accton-ofdpa3", true)
45 .put("znyx-ofdpa", true)
46 .build();
Andrea Campanella4c6170a2018-01-17 16:34:51 +010047
48 /**
49 * Checks if the Mac Address is inside a range between the min MAC and the mask.
50 * @param macAddress the MAC address to check
51 * @param minAddr the min MAC address
52 * @param maskAddr the mask
53 * @return true if in range, false otherwise.
54 */
55 static boolean compareMac(MacAddress macAddress, MacAddress minAddr, MacAddress maskAddr) {
56 byte[] mac = macAddress.toBytes();
57 byte[] min = minAddr.toBytes();
58 byte[] mask = maskAddr.toBytes();
59 boolean inRange = true;
60
61 int i = 0;
62
63 //if mask is 00 stop
64 while (inRange && i < mask.length && (mask[i] & 0xFF) != 0) {
65 int ibmac = mac[i] & 0xFF;
66 int ibmin = min[i] & 0xFF;
67 int ibmask = mask[i] & 0xFF;
68 if (ibmask == 255) {
69 inRange = ibmac == ibmin;
70 } else if (ibmac < ibmin || ibmac >= ibmask) {
71 inRange = false;
72 break;
73 }
74 i++;
75 }
76
77 return inRange;
78 }
Andrea Campanellae4084402017-12-15 15:27:31 +010079}