blob: 17a78b6e34ea43a82ddc86fc0b9e1f740e6f37ff [file] [log] [blame]
Charles Chand55e84d2016-03-30 17:54:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Charles Chand55e84d2016-03-30 17:54:24 -07003 *
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
Ray Milkey6c1f0f02017-08-15 11:02:29 -070017package org.onosproject.net.config.basics;
Charles Chand55e84d2016-03-30 17:54:24 -070018
19import com.google.common.annotations.Beta;
20import org.onlab.packet.VlanId;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.config.Config;
23
24/**
25 * Configuration for multicast.
26 */
27@Beta
28public class McastConfig extends Config<ApplicationId> {
29 private static final String INGRESS_VLAN = "ingressVlan";
30 private static final String EGRESS_VLAN = "egressVlan";
Esin Karaman89f6edf2020-03-13 13:57:25 +000031 private static final String EGRESS_INNER_VLAN = "egressInnerVlan";
Charles Chand55e84d2016-03-30 17:54:24 -070032
33 @Override
34 public boolean isValid() {
Esin Karaman89f6edf2020-03-13 13:57:25 +000035 return hasOnlyFields(INGRESS_VLAN, EGRESS_VLAN, EGRESS_INNER_VLAN) &&
36 ingressVlan() != null && egressVlan() != null && egressInnerVlan() != null;
Charles Chand55e84d2016-03-30 17:54:24 -070037 }
38
39 /**
40 * Gets ingress VLAN of multicast traffic.
41 *
42 * @return Ingress VLAN ID
43 */
44 public VlanId ingressVlan() {
45 if (!object.has(INGRESS_VLAN)) {
46 return VlanId.NONE;
47 }
48
49 try {
50 return VlanId.vlanId(object.path(INGRESS_VLAN).asText());
51 } catch (IllegalArgumentException e) {
52 return null;
53 }
54 }
55
56 /**
57 * Sets ingress VLAN of multicast traffic.
58 *
59 * @param vlanId Ingress VLAN ID
60 * @return this {@link McastConfig}
61 */
62 public McastConfig setIngressVlan(VlanId vlanId) {
63 if (vlanId == null) {
64 object.remove(INGRESS_VLAN);
65 } else {
66 object.put(INGRESS_VLAN, vlanId.toString());
67 }
68 return this;
69 }
70
71 /**
72 * Gets egress VLAN of multicast traffic.
73 *
74 * @return Egress VLAN ID
75 */
76 public VlanId egressVlan() {
77 if (!object.has(EGRESS_VLAN)) {
78 return VlanId.NONE;
79 }
80
81 try {
82 return VlanId.vlanId(object.path(EGRESS_VLAN).asText());
83 } catch (IllegalArgumentException e) {
84 return null;
85 }
86 }
87
88 /**
89 * Sets egress VLAN of multicast traffic.
90 *
91 * @param vlanId Egress VLAN ID
92 * @return this {@link McastConfig}
93 */
94 public McastConfig setEgressVlan(VlanId vlanId) {
95 if (vlanId == null) {
96 object.remove(EGRESS_VLAN);
97 } else {
98 object.put(EGRESS_VLAN, vlanId.toString());
99 }
100 return this;
101 }
Esin Karaman89f6edf2020-03-13 13:57:25 +0000102
103 /**
104 * Gets egress inner VLAN of multicast traffic.
105 *
106 * @return Egress inner VLAN ID
107 */
108 public VlanId egressInnerVlan() {
109 if (!object.has(EGRESS_INNER_VLAN)) {
110 return VlanId.NONE;
111 }
112
113 try {
114 return VlanId.vlanId(object.path(EGRESS_INNER_VLAN).asText());
115 } catch (IllegalArgumentException e) {
116 return null;
117 }
118 }
119
120 /**
121 * Sets egress inner VLAN of multicast traffic.
122 *
123 * @param vlanId Egress inner VLAN ID
124 * @return this {@link McastConfig}
125 */
126 public McastConfig setEgressInnerVlan(VlanId vlanId) {
127 if (vlanId == null) {
128 object.remove(EGRESS_INNER_VLAN);
129 } else {
130 object.put(EGRESS_INNER_VLAN, vlanId.toString());
131 }
132 return this;
133 }
Charles Chand55e84d2016-03-30 17:54:24 -0700134}