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"; |
| 31 | |
| 32 | @Override |
| 33 | public boolean isValid() { |
| 34 | return hasOnlyFields(INGRESS_VLAN, EGRESS_VLAN) && |
| 35 | ingressVlan() != null && egressVlan() != null; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Gets ingress VLAN of multicast traffic. |
| 40 | * |
| 41 | * @return Ingress VLAN ID |
| 42 | */ |
| 43 | public VlanId ingressVlan() { |
| 44 | if (!object.has(INGRESS_VLAN)) { |
| 45 | return VlanId.NONE; |
| 46 | } |
| 47 | |
| 48 | try { |
| 49 | return VlanId.vlanId(object.path(INGRESS_VLAN).asText()); |
| 50 | } catch (IllegalArgumentException e) { |
| 51 | return null; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Sets ingress VLAN of multicast traffic. |
| 57 | * |
| 58 | * @param vlanId Ingress VLAN ID |
| 59 | * @return this {@link McastConfig} |
| 60 | */ |
| 61 | public McastConfig setIngressVlan(VlanId vlanId) { |
| 62 | if (vlanId == null) { |
| 63 | object.remove(INGRESS_VLAN); |
| 64 | } else { |
| 65 | object.put(INGRESS_VLAN, vlanId.toString()); |
| 66 | } |
| 67 | return this; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Gets egress VLAN of multicast traffic. |
| 72 | * |
| 73 | * @return Egress VLAN ID |
| 74 | */ |
| 75 | public VlanId egressVlan() { |
| 76 | if (!object.has(EGRESS_VLAN)) { |
| 77 | return VlanId.NONE; |
| 78 | } |
| 79 | |
| 80 | try { |
| 81 | return VlanId.vlanId(object.path(EGRESS_VLAN).asText()); |
| 82 | } catch (IllegalArgumentException e) { |
| 83 | return null; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Sets egress VLAN of multicast traffic. |
| 89 | * |
| 90 | * @param vlanId Egress VLAN ID |
| 91 | * @return this {@link McastConfig} |
| 92 | */ |
| 93 | public McastConfig setEgressVlan(VlanId vlanId) { |
| 94 | if (vlanId == null) { |
| 95 | object.remove(EGRESS_VLAN); |
| 96 | } else { |
| 97 | object.put(EGRESS_VLAN, vlanId.toString()); |
| 98 | } |
| 99 | return this; |
| 100 | } |
| 101 | } |