blob: 097fa92ae4980bfe5283bbce564e18c8acf91ec6 [file] [log] [blame]
Andrea Campanella01e886e2017-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 Campanella04924b92018-01-17 16:34:51 +010020import org.onlab.packet.MacAddress;
Andrea Campanella01e886e2017-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)
shaohua.xionga5b942d2018-11-28 11:05:45 +080045 .put("delta-ofdpa3", true)
Andrea Campanella01e886e2017-12-15 15:27:31 +010046 .put("znyx-ofdpa", true)
47 .build();
Andrea Campanella04924b92018-01-17 16:34:51 +010048
49 /**
50 * Checks if the Mac Address is inside a range between the min MAC and the mask.
51 * @param macAddress the MAC address to check
52 * @param minAddr the min MAC address
53 * @param maskAddr the mask
54 * @return true if in range, false otherwise.
55 */
56 static boolean compareMac(MacAddress macAddress, MacAddress minAddr, MacAddress maskAddr) {
57 byte[] mac = macAddress.toBytes();
58 byte[] min = minAddr.toBytes();
59 byte[] mask = maskAddr.toBytes();
60 boolean inRange = true;
61
62 int i = 0;
63
64 //if mask is 00 stop
65 while (inRange && i < mask.length && (mask[i] & 0xFF) != 0) {
66 int ibmac = mac[i] & 0xFF;
67 int ibmin = min[i] & 0xFF;
68 int ibmask = mask[i] & 0xFF;
69 if (ibmask == 255) {
70 inRange = ibmac == ibmin;
71 } else if (ibmac < ibmin || ibmac >= ibmask) {
72 inRange = false;
73 break;
74 }
75 i++;
76 }
77
78 return inRange;
79 }
Andrea Campanella01e886e2017-12-15 15:27:31 +010080}