Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 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 | |
Ray Milkey | 6c1f0f0 | 2017-08-15 11:02:29 -0700 | [diff] [blame] | 17 | package org.onosproject.net.config.basics; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onlab.packet.VlanId; |
| 21 | import org.onosproject.core.ApplicationId; |
| 22 | import org.onosproject.net.config.Config; |
| 23 | |
| 24 | /** |
| 25 | * Configuration for multicast. |
| 26 | */ |
| 27 | @Beta |
| 28 | public class McastConfig extends Config<ApplicationId> { |
| 29 | private static final String INGRESS_VLAN = "ingressVlan"; |
| 30 | private static final String EGRESS_VLAN = "egressVlan"; |
Esin Karaman | 89f6edf | 2020-03-13 13:57:25 +0000 | [diff] [blame] | 31 | private static final String EGRESS_INNER_VLAN = "egressInnerVlan"; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 32 | |
| 33 | @Override |
| 34 | public boolean isValid() { |
Esin Karaman | 89f6edf | 2020-03-13 13:57:25 +0000 | [diff] [blame] | 35 | return hasOnlyFields(INGRESS_VLAN, EGRESS_VLAN, EGRESS_INNER_VLAN) && |
| 36 | ingressVlan() != null && egressVlan() != null && egressInnerVlan() != null; |
Charles Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 37 | } |
| 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 Karaman | 89f6edf | 2020-03-13 13:57:25 +0000 | [diff] [blame] | 102 | |
| 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 Chan | d55e84d | 2016-03-30 17:54:24 -0700 | [diff] [blame] | 134 | } |