Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.t3.impl; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableMap; |
Andrea Campanella | 04924b9 | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 20 | import org.onlab.packet.MacAddress; |
Andrea Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 21 | |
| 22 | import java.util.Map; |
| 23 | |
| 24 | /** |
| 25 | * Utility class for the troubleshooting tool. |
| 26 | */ |
| 27 | final 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 Campanella | 04924b9 | 2018-01-17 16:34:51 +0100 | [diff] [blame] | 47 | |
| 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 Campanella | 01e886e | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 79 | } |