Add configuration for default vlan
Change-Id: I183def6d1de3d10b2f53895f7fb7723df315379f
Showing
3 changed files
with
36 additions
and
7 deletions
... | @@ -16,11 +16,14 @@ | ... | @@ -16,11 +16,14 @@ |
16 | 16 | ||
17 | package org.onosproject.olt; | 17 | package org.onosproject.olt; |
18 | 18 | ||
19 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
20 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
21 | import org.onosproject.net.PortNumber; | 22 | import org.onosproject.net.PortNumber; |
22 | import org.onosproject.net.config.Config; | 23 | import org.onosproject.net.config.Config; |
23 | 24 | ||
25 | +import java.util.Optional; | ||
26 | + | ||
24 | /** | 27 | /** |
25 | * Config object for access device data. | 28 | * Config object for access device data. |
26 | */ | 29 | */ |
... | @@ -28,6 +31,7 @@ public class AccessDeviceConfig extends Config<DeviceId> { | ... | @@ -28,6 +31,7 @@ public class AccessDeviceConfig extends Config<DeviceId> { |
28 | 31 | ||
29 | private static final String UPLINK = "uplink"; | 32 | private static final String UPLINK = "uplink"; |
30 | private static final String VLAN = "vlan"; | 33 | private static final String VLAN = "vlan"; |
34 | + private static final String DEFAULT_VLAN = "defaultVlan"; | ||
31 | 35 | ||
32 | /** | 36 | /** |
33 | * Gets the access device configuration for this device. | 37 | * Gets the access device configuration for this device. |
... | @@ -37,7 +41,15 @@ public class AccessDeviceConfig extends Config<DeviceId> { | ... | @@ -37,7 +41,15 @@ public class AccessDeviceConfig extends Config<DeviceId> { |
37 | public AccessDeviceData getOlt() { | 41 | public AccessDeviceData getOlt() { |
38 | PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); | 42 | PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); |
39 | VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); | 43 | VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); |
44 | + JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); | ||
45 | + | ||
46 | + Optional<VlanId> defaultVlan; | ||
47 | + if (defaultVlanNode.isMissingNode()) { | ||
48 | + defaultVlan = Optional.empty(); | ||
49 | + } else { | ||
50 | + defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); | ||
51 | + } | ||
40 | 52 | ||
41 | - return new AccessDeviceData(subject(), uplink, vlan); | 53 | + return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); |
42 | } | 54 | } |
43 | } | 55 | } | ... | ... |
... | @@ -20,6 +20,8 @@ import org.onlab.packet.VlanId; | ... | @@ -20,6 +20,8 @@ import org.onlab.packet.VlanId; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | import org.onosproject.net.PortNumber; | 21 | import org.onosproject.net.PortNumber; |
22 | 22 | ||
23 | +import java.util.Optional; | ||
24 | + | ||
23 | import static com.google.common.base.Preconditions.checkNotNull; | 25 | import static com.google.common.base.Preconditions.checkNotNull; |
24 | 26 | ||
25 | /** | 27 | /** |
... | @@ -33,6 +35,7 @@ public class AccessDeviceData { | ... | @@ -33,6 +35,7 @@ public class AccessDeviceData { |
33 | private final DeviceId deviceId; | 35 | private final DeviceId deviceId; |
34 | private final PortNumber uplink; | 36 | private final PortNumber uplink; |
35 | private final VlanId vlan; | 37 | private final VlanId vlan; |
38 | + private final Optional<VlanId> defaultVlan; | ||
36 | 39 | ||
37 | /** | 40 | /** |
38 | * Class constructor. | 41 | * Class constructor. |
... | @@ -41,10 +44,12 @@ public class AccessDeviceData { | ... | @@ -41,10 +44,12 @@ public class AccessDeviceData { |
41 | * @param uplink uplink port number | 44 | * @param uplink uplink port number |
42 | * @param vlan device VLAN ID | 45 | * @param vlan device VLAN ID |
43 | */ | 46 | */ |
44 | - public AccessDeviceData(DeviceId deviceId, PortNumber uplink, VlanId vlan) { | 47 | + public AccessDeviceData(DeviceId deviceId, PortNumber uplink, VlanId vlan, |
48 | + Optional<VlanId> defaultVlan) { | ||
45 | this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING); | 49 | this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING); |
46 | this.uplink = checkNotNull(uplink, UPLINK_MISSING); | 50 | this.uplink = checkNotNull(uplink, UPLINK_MISSING); |
47 | this.vlan = checkNotNull(vlan, VLAN_MISSING); | 51 | this.vlan = checkNotNull(vlan, VLAN_MISSING); |
52 | + this.defaultVlan = checkNotNull(defaultVlan); | ||
48 | } | 53 | } |
49 | 54 | ||
50 | /** | 55 | /** |
... | @@ -68,9 +73,18 @@ public class AccessDeviceData { | ... | @@ -68,9 +73,18 @@ public class AccessDeviceData { |
68 | /** | 73 | /** |
69 | * Retrieves the VLAN ID assigned to the device. | 74 | * Retrieves the VLAN ID assigned to the device. |
70 | * | 75 | * |
71 | - * @return vlan ID | 76 | + * @return VLAN ID |
72 | */ | 77 | */ |
73 | public VlanId vlan() { | 78 | public VlanId vlan() { |
74 | return vlan; | 79 | return vlan; |
75 | } | 80 | } |
81 | + | ||
82 | + /** | ||
83 | + * Retrieves the default VLAN ID that will be used for this device. | ||
84 | + * | ||
85 | + * @return default VLAN ID | ||
86 | + */ | ||
87 | + public Optional<VlanId> defaultVlan() { | ||
88 | + return defaultVlan; | ||
89 | + } | ||
76 | } | 90 | } | ... | ... |
... | @@ -52,6 +52,7 @@ import org.slf4j.Logger; | ... | @@ -52,6 +52,7 @@ import org.slf4j.Logger; |
52 | 52 | ||
53 | import java.util.Dictionary; | 53 | import java.util.Dictionary; |
54 | import java.util.Map; | 54 | import java.util.Map; |
55 | +import java.util.Optional; | ||
55 | import java.util.concurrent.ConcurrentHashMap; | 56 | import java.util.concurrent.ConcurrentHashMap; |
56 | 57 | ||
57 | import static org.slf4j.LoggerFactory.getLogger; | 58 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -247,15 +248,17 @@ public class OLT implements AccessDeviceService { | ... | @@ -247,15 +248,17 @@ public class OLT implements AccessDeviceService { |
247 | return; | 248 | return; |
248 | } | 249 | } |
249 | 250 | ||
250 | - provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan()); | 251 | + provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan(), |
252 | + olt.defaultVlan()); | ||
251 | } | 253 | } |
252 | 254 | ||
253 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, | 255 | private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, |
254 | PortNumber subscriberPort, | 256 | PortNumber subscriberPort, |
255 | - VlanId subscriberVlan, VlanId deviceVlan) { | 257 | + VlanId subscriberVlan, VlanId deviceVlan, |
258 | + Optional<VlanId> defaultVlan) { | ||
256 | 259 | ||
257 | TrafficSelector upstream = DefaultTrafficSelector.builder() | 260 | TrafficSelector upstream = DefaultTrafficSelector.builder() |
258 | - .matchVlanId(DEFAULT_VLAN) | 261 | + .matchVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN) |
259 | .matchInPort(subscriberPort) | 262 | .matchInPort(subscriberPort) |
260 | .build(); | 263 | .build(); |
261 | 264 | ||
... | @@ -273,7 +276,7 @@ public class OLT implements AccessDeviceService { | ... | @@ -273,7 +276,7 @@ public class OLT implements AccessDeviceService { |
273 | 276 | ||
274 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() | 277 | TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() |
275 | .popVlan() | 278 | .popVlan() |
276 | - .setVlanId(DEFAULT_VLAN) | 279 | + .setVlanId((defaultVlan.isPresent()) ? defaultVlan.get() : DEFAULT_VLAN) |
277 | .setOutput(subscriberPort) | 280 | .setOutput(subscriberPort) |
278 | .build(); | 281 | .build(); |
279 | 282 | ... | ... |
-
Please register or login to post a comment