blob: d18fb6f8f9ef4267ae75f9cf202d52439b1ef61c [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-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 */
16package org.onosproject.incubator.net.l2monitoring.cfm.identifier;
17
18/**
19 * The 2 octet format of MA Short Name.
20 * This is similar to primaryVid except range is 0 to 65535
21 */
22public final class MaId2Octet extends MaIdPrimaryVid {
23 protected static int uintUpperLimit = 65535;
24
25 protected MaId2Octet(int id2octet) {
26 super(id2octet);
27 }
28
29 public static MaIdShort asMaId(int id) {
30 if (id <= lowerLimit || id > uintUpperLimit) {
31 throw new IllegalArgumentException("MA Id must be between " +
32 lowerLimit + " and " + uintUpperLimit + ". Rejecting: " + id);
33 }
34 return new MaId2Octet(id);
35 }
36
37 public static MaIdShort asMaId(String maName) {
38 int id = 0;
39 try {
40 id = Integer.parseInt(maName);
41 return asMaId(id);
42 } catch (NumberFormatException e) {
43 throw new IllegalArgumentException("MA Name must be numeric. Rejecting: " +
44 maName + " " + e.getMessage());
45 }
46 }
47
48 @Override
49 public MaIdType nameType() {
50 return MaIdType.TWOOCTET;
51 }
52}