alshabib
Committed by Gerrit Code Review

cleaning up more cord apps

Change-Id: Ie48245b61926232ca9b2fa583492cb6e88f10990
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2016 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="${project.artifactId}" version="${project.version}"
19 + description="${project.description}">
20 + <feature>onos-api</feature>
21 + <bundle>mvn:${project.groupId}/onos-app-olt-api/${project.version}</bundle>
22 + <bundle>mvn:${project.groupId}/onos-app-cord-mcast/${project.version}</bundle>
23 + </feature>
24 +</features>
...@@ -68,5 +68,10 @@ ...@@ -68,5 +68,10 @@
68 <artifactId>jersey-client</artifactId> 68 <artifactId>jersey-client</artifactId>
69 <version>1.19</version> 69 <version>1.19</version>
70 </dependency> 70 </dependency>
71 + <dependency>
72 + <groupId>org.onosproject</groupId>
73 + <artifactId>onos-app-olt-api</artifactId>
74 + <version>${project.version}</version>
75 + </dependency>
71 </dependencies> 76 </dependencies>
72 </project> 77 </project>
......
...@@ -24,6 +24,7 @@ import com.sun.jersey.api.client.Client; ...@@ -24,6 +24,7 @@ import com.sun.jersey.api.client.Client;
24 import com.sun.jersey.api.client.ClientHandlerException; 24 import com.sun.jersey.api.client.ClientHandlerException;
25 import com.sun.jersey.api.client.WebResource; 25 import com.sun.jersey.api.client.WebResource;
26 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; 26 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
27 +import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
28 import org.apache.felix.scr.annotations.Component; 29 import org.apache.felix.scr.annotations.Component;
29 import org.apache.felix.scr.annotations.Deactivate; 30 import org.apache.felix.scr.annotations.Deactivate;
...@@ -40,6 +41,12 @@ import org.onosproject.codec.JsonCodec; ...@@ -40,6 +41,12 @@ import org.onosproject.codec.JsonCodec;
40 import org.onosproject.core.ApplicationId; 41 import org.onosproject.core.ApplicationId;
41 import org.onosproject.core.CoreService; 42 import org.onosproject.core.CoreService;
42 import org.onosproject.net.ConnectPoint; 43 import org.onosproject.net.ConnectPoint;
44 +import org.onosproject.net.DeviceId;
45 +import org.onosproject.net.config.ConfigFactory;
46 +import org.onosproject.net.config.NetworkConfigEvent;
47 +import org.onosproject.net.config.NetworkConfigListener;
48 +import org.onosproject.net.config.NetworkConfigRegistry;
49 +import org.onosproject.net.config.basics.SubjectFactories;
43 import org.onosproject.net.flow.DefaultTrafficSelector; 50 import org.onosproject.net.flow.DefaultTrafficSelector;
44 import org.onosproject.net.flow.DefaultTrafficTreatment; 51 import org.onosproject.net.flow.DefaultTrafficTreatment;
45 import org.onosproject.net.flow.TrafficSelector; 52 import org.onosproject.net.flow.TrafficSelector;
...@@ -56,6 +63,8 @@ import org.onosproject.net.mcast.McastListener; ...@@ -56,6 +63,8 @@ import org.onosproject.net.mcast.McastListener;
56 import org.onosproject.net.mcast.McastRoute; 63 import org.onosproject.net.mcast.McastRoute;
57 import org.onosproject.net.mcast.McastRouteInfo; 64 import org.onosproject.net.mcast.McastRouteInfo;
58 import org.onosproject.net.mcast.MulticastRouteService; 65 import org.onosproject.net.mcast.MulticastRouteService;
66 +import org.onosproject.olt.AccessDeviceConfig;
67 +import org.onosproject.olt.AccessDeviceData;
59 import org.onosproject.rest.AbstractWebResource; 68 import org.onosproject.rest.AbstractWebResource;
60 import org.osgi.service.component.ComponentContext; 69 import org.osgi.service.component.ComponentContext;
61 import org.slf4j.Logger; 70 import org.slf4j.Logger;
...@@ -66,7 +75,7 @@ import java.util.Dictionary; ...@@ -66,7 +75,7 @@ import java.util.Dictionary;
66 import java.util.List; 75 import java.util.List;
67 import java.util.Map; 76 import java.util.Map;
68 import java.util.Properties; 77 import java.util.Properties;
69 -import java.util.Set; 78 +import java.util.concurrent.ConcurrentHashMap;
70 import java.util.concurrent.atomic.AtomicBoolean; 79 import java.util.concurrent.atomic.AtomicBoolean;
71 import java.util.concurrent.atomic.AtomicInteger; 80 import java.util.concurrent.atomic.AtomicInteger;
72 81
...@@ -84,12 +93,14 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -84,12 +93,14 @@ import static org.slf4j.LoggerFactory.getLogger;
84 @Component(immediate = true) 93 @Component(immediate = true)
85 public class CordMcast { 94 public class CordMcast {
86 95
96 +
87 private static final int DEFAULT_REST_TIMEOUT_MS = 2000; 97 private static final int DEFAULT_REST_TIMEOUT_MS = 2000;
88 - private static final int DEFAULT_PRIORITY = 1000; 98 + private static final int DEFAULT_PRIORITY = 500;
89 private static final short DEFAULT_MCAST_VLAN = 4000; 99 private static final short DEFAULT_MCAST_VLAN = 4000;
90 private static final String DEFAULT_SYNC_HOST = "10.90.0.8:8181"; 100 private static final String DEFAULT_SYNC_HOST = "10.90.0.8:8181";
91 private static final String DEFAULT_USER = "karaf"; 101 private static final String DEFAULT_USER = "karaf";
92 private static final String DEFAULT_PASSWORD = "karaf"; 102 private static final String DEFAULT_PASSWORD = "karaf";
103 + private static final boolean DEFAULT_VLAN_ENABLED = true;
93 104
94 private final Logger log = getLogger(getClass()); 105 private final Logger log = getLogger(getClass());
95 106
...@@ -108,7 +119,12 @@ public class CordMcast { ...@@ -108,7 +119,12 @@ public class CordMcast {
108 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 119 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
109 protected ComponentConfigService componentConfigService; 120 protected ComponentConfigService componentConfigService;
110 121
122 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
123 + protected NetworkConfigRegistry networkConfig;
124 +
111 protected McastListener listener = new InternalMulticastListener(); 125 protected McastListener listener = new InternalMulticastListener();
126 + private InternalNetworkConfigListener configListener =
127 + new InternalNetworkConfigListener();
112 128
113 //TODO: move this to a ec map 129 //TODO: move this to a ec map
114 private Map<IpAddress, Integer> groups = Maps.newConcurrentMap(); 130 private Map<IpAddress, Integer> groups = Maps.newConcurrentMap();
...@@ -122,9 +138,9 @@ public class CordMcast { ...@@ -122,9 +138,9 @@ public class CordMcast {
122 label = "VLAN for multicast traffic") 138 label = "VLAN for multicast traffic")
123 private int mcastVlan = DEFAULT_MCAST_VLAN; 139 private int mcastVlan = DEFAULT_MCAST_VLAN;
124 140
125 - @Property(name = "vlanEnabled", boolValue = false, 141 + @Property(name = "vlanEnabled", boolValue = DEFAULT_VLAN_ENABLED,
126 - label = "Use vlan for multicast traffic") 142 + label = "Use vlan for multicast traffic?")
127 - private boolean vlanEnabled = false; 143 + private boolean vlanEnabled = DEFAULT_VLAN_ENABLED;
128 144
129 @Property(name = "priority", intValue = DEFAULT_PRIORITY, 145 @Property(name = "priority", intValue = DEFAULT_PRIORITY,
130 label = "Priority for multicast rules") 146 label = "Priority for multicast rules")
...@@ -144,6 +160,20 @@ public class CordMcast { ...@@ -144,6 +160,20 @@ public class CordMcast {
144 160
145 private String fabricOnosUrl; 161 private String fabricOnosUrl;
146 162
163 + private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>();
164 +
165 + private static final Class<AccessDeviceConfig> CONFIG_CLASS =
166 + AccessDeviceConfig.class;
167 +
168 + private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory =
169 + new ConfigFactory<DeviceId, AccessDeviceConfig>(
170 + SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") {
171 + @Override
172 + public AccessDeviceConfig createConfig() {
173 + return new AccessDeviceConfig();
174 + }
175 + };
176 +
147 @Activate 177 @Activate
148 public void activate(ComponentContext context) { 178 public void activate(ComponentContext context) {
149 componentConfigService.registerProperties(getClass()); 179 componentConfigService.registerProperties(getClass());
...@@ -151,16 +181,30 @@ public class CordMcast { ...@@ -151,16 +181,30 @@ public class CordMcast {
151 181
152 appId = coreService.registerApplication("org.onosproject.cordmcast"); 182 appId = coreService.registerApplication("org.onosproject.cordmcast");
153 183
184 +
154 clearRemoteRoutes(); 185 clearRemoteRoutes();
155 186
156 - mcastService.addListener(listener); 187 + networkConfig.registerConfigFactory(configFactory);
188 + networkConfig.addListener(configListener);
157 189
158 - for (McastRoute route : mcastService.getRoutes()) { 190 + networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach(
159 - Set<ConnectPoint> sinks = mcastService.fetchSinks(route); 191 + subject -> {
160 - if (!sinks.isEmpty()) { 192 + AccessDeviceConfig config = networkConfig.getConfig(subject, AccessDeviceConfig.class);
161 - sinks.forEach(s -> provisionGroup(route, s)); 193 + if (config != null) {
194 + AccessDeviceData data = config.getOlt();
195 + oltData.put(data.deviceId(), data);
162 } 196 }
163 } 197 }
198 + );
199 +
200 +
201 + mcastService.addListener(listener);
202 +
203 + mcastService.getRoutes().stream()
204 + .map(r -> new ImmutablePair<>(r, mcastService.fetchSinks(r)))
205 + .filter(pair -> pair.getRight() != null && !pair.getRight().isEmpty())
206 + .forEach(pair -> pair.getRight().forEach(sink -> provisionGroup(pair.getLeft(),
207 + sink)));
164 208
165 log.info("Started"); 209 log.info("Started");
166 } 210 }
...@@ -169,6 +213,8 @@ public class CordMcast { ...@@ -169,6 +213,8 @@ public class CordMcast {
169 public void deactivate() { 213 public void deactivate() {
170 componentConfigService.unregisterProperties(getClass(), false); 214 componentConfigService.unregisterProperties(getClass(), false);
171 mcastService.removeListener(listener); 215 mcastService.removeListener(listener);
216 + networkConfig.unregisterConfigFactory(configFactory);
217 + networkConfig.removeListener(configListener);
172 log.info("Stopped"); 218 log.info("Stopped");
173 } 219 }
174 220
...@@ -187,7 +233,7 @@ public class CordMcast { ...@@ -187,7 +233,7 @@ public class CordMcast {
187 mcastVlan = isNullOrEmpty(s) ? DEFAULT_MCAST_VLAN : Short.parseShort(s.trim()); 233 mcastVlan = isNullOrEmpty(s) ? DEFAULT_MCAST_VLAN : Short.parseShort(s.trim());
188 234
189 s = get(properties, "vlanEnabled"); 235 s = get(properties, "vlanEnabled");
190 - vlanEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); 236 + vlanEnabled = isNullOrEmpty(s) ? DEFAULT_VLAN_ENABLED : Boolean.parseBoolean(s.trim());
191 237
192 s = get(properties, "priority"); 238 s = get(properties, "priority");
193 priority = isNullOrEmpty(s) ? DEFAULT_PRIORITY : Integer.parseInt(s.trim()); 239 priority = isNullOrEmpty(s) ? DEFAULT_PRIORITY : Integer.parseInt(s.trim());
...@@ -275,6 +321,13 @@ public class CordMcast { ...@@ -275,6 +321,13 @@ public class CordMcast {
275 checkNotNull(route, "Route cannot be null"); 321 checkNotNull(route, "Route cannot be null");
276 checkNotNull(sink, "Sink cannot be null"); 322 checkNotNull(sink, "Sink cannot be null");
277 323
324 + AccessDeviceData oltInfo = oltData.get(sink.deviceId());
325 +
326 + if (oltInfo == null) {
327 + log.warn("Unknown OLT device : {}", sink.deviceId());
328 + return;
329 + }
330 +
278 final AtomicBoolean sync = new AtomicBoolean(false); 331 final AtomicBoolean sync = new AtomicBoolean(false);
279 332
280 Integer nextId = groups.computeIfAbsent(route.group(), (g) -> { 333 Integer nextId = groups.computeIfAbsent(route.group(), (g) -> {
...@@ -304,6 +357,7 @@ public class CordMcast { ...@@ -304,6 +357,7 @@ public class CordMcast {
304 flowObjectiveService.next(sink.deviceId(), next); 357 flowObjectiveService.next(sink.deviceId(), next);
305 358
306 TrafficSelector.Builder mcast = DefaultTrafficSelector.builder() 359 TrafficSelector.Builder mcast = DefaultTrafficSelector.builder()
360 + .matchInPort(oltInfo.uplink())
307 .matchEthType(Ethernet.TYPE_IPV4) 361 .matchEthType(Ethernet.TYPE_IPV4)
308 .matchIPDst(g.toIpPrefix()); 362 .matchIPDst(g.toIpPrefix());
309 363
...@@ -364,6 +418,7 @@ public class CordMcast { ...@@ -364,6 +418,7 @@ public class CordMcast {
364 flowObjectiveService.next(sink.deviceId(), next); 418 flowObjectiveService.next(sink.deviceId(), next);
365 } 419 }
366 420
421 +
367 addRemoteRoute(route); 422 addRemoteRoute(route);
368 } 423 }
369 424
...@@ -456,4 +511,37 @@ public class CordMcast { ...@@ -456,4 +511,37 @@ public class CordMcast {
456 .type(JSON_UTF_8.toString()); 511 .type(JSON_UTF_8.toString());
457 } 512 }
458 513
514 + private class InternalNetworkConfigListener implements NetworkConfigListener {
515 + @Override
516 + public void event(NetworkConfigEvent event) {
517 + switch (event.type()) {
518 +
519 + case CONFIG_ADDED:
520 + case CONFIG_UPDATED:
521 + AccessDeviceConfig config =
522 + networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
523 + if (config != null) {
524 + oltData.put(config.getOlt().deviceId(), config.getOlt());
525 + }
526 +
527 + break;
528 + case CONFIG_REGISTERED:
529 + case CONFIG_UNREGISTERED:
530 + break;
531 + case CONFIG_REMOVED:
532 + oltData.remove(event.subject());
533 + break;
534 + default:
535 + break;
536 + }
537 + }
538 +
539 + @Override
540 + public boolean isRelevant(NetworkConfigEvent event) {
541 + return event.configClass().equals(CONFIG_CLASS);
542 + }
543 +
544 +
545 + }
546 +
459 } 547 }
......
...@@ -528,7 +528,10 @@ public class IgmpSnoop { ...@@ -528,7 +528,10 @@ public class IgmpSnoop {
528 case CONFIG_REMOVED: 528 case CONFIG_REMOVED:
529 if (event.configClass().equals(SSM_TRANSLATE_CONFIG_CLASS)) { 529 if (event.configClass().equals(SSM_TRANSLATE_CONFIG_CLASS)) {
530 ssmTranslateTable.clear(); 530 ssmTranslateTable.clear();
531 + } else if (event.configClass().equals(CONFIG_CLASS)) {
532 + oltData.remove(event.subject());
531 } 533 }
534 +
532 default: 535 default:
533 break; 536 break;
534 } 537 }
......
...@@ -19,6 +19,9 @@ package org.onosproject.olt; ...@@ -19,6 +19,9 @@ package org.onosproject.olt;
19 import org.onlab.packet.VlanId; 19 import org.onlab.packet.VlanId;
20 import org.onosproject.event.ListenerService; 20 import org.onosproject.event.ListenerService;
21 import org.onosproject.net.ConnectPoint; 21 import org.onosproject.net.ConnectPoint;
22 +import org.onosproject.net.DeviceId;
23 +
24 +import java.util.Map;
22 25
23 /** 26 /**
24 * Service for interacting with an access device (OLT). 27 * Service for interacting with an access device (OLT).
...@@ -41,4 +44,11 @@ public interface AccessDeviceService ...@@ -41,4 +44,11 @@ public interface AccessDeviceService
41 */ 44 */
42 void removeSubscriber(ConnectPoint port); 45 void removeSubscriber(ConnectPoint port);
43 46
47 + /**
48 + * Returns the map of configured OLTs.
49 + *
50 + * @return a map
51 + */
52 + Map<DeviceId, AccessDeviceData> fetchOlts();
53 +
44 } 54 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
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 +
17 +package org.onosproject.olt.cli;
18 +
19 +import org.apache.karaf.shell.commands.Argument;
20 +import org.apache.karaf.shell.commands.Command;
21 +import org.onosproject.cli.AbstractShellCommand;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.olt.AccessDeviceData;
24 +import org.onosproject.olt.AccessDeviceService;
25 +
26 +import java.util.Map;
27 +
28 +/**
29 + * Adds a subscriber to an access device.
30 + */
31 +@Command(scope = "onos", name = "show-olts",
32 + description = "Shows configured OLTs")
33 +public class ShowOltCommand extends AbstractShellCommand {
34 +
35 + @Argument(index = 0, name = "deviceId", description = "Access device ID",
36 + required = false, multiValued = false)
37 + private String strDeviceId = null;
38 +
39 + @Override
40 + protected void execute() {
41 + AccessDeviceService service = AbstractShellCommand.get(AccessDeviceService.class);
42 + Map<DeviceId, AccessDeviceData> data = service.fetchOlts();
43 + if (strDeviceId != null) {
44 + DeviceId deviceId = DeviceId.deviceId(strDeviceId);
45 + print("OLT %s:", deviceId);
46 + display(data.get(deviceId));
47 + } else {
48 + data.keySet().forEach(did -> {
49 + print("OLT %s:", did);
50 + display(data.get(did));
51 + });
52 + }
53 + }
54 +
55 + private void display(AccessDeviceData accessDeviceData) {
56 + print("\tvlan : %s", accessDeviceData.vlan());
57 + print("\tuplink : %s", accessDeviceData.uplink());
58 + }
59 +}
...@@ -20,11 +20,14 @@ import com.google.common.collect.Sets; ...@@ -20,11 +20,14 @@ import com.google.common.collect.Sets;
20 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
22 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
23 +import org.apache.felix.scr.annotations.Modified;
24 +import org.apache.felix.scr.annotations.Property;
23 import org.apache.felix.scr.annotations.Reference; 25 import org.apache.felix.scr.annotations.Reference;
24 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
26 import org.onlab.packet.EthType; 28 import org.onlab.packet.EthType;
27 import org.onlab.packet.VlanId; 29 import org.onlab.packet.VlanId;
30 +import org.onosproject.cfg.ComponentConfigService;
28 import org.onosproject.core.ApplicationId; 31 import org.onosproject.core.ApplicationId;
29 import org.onosproject.core.CoreService; 32 import org.onosproject.core.CoreService;
30 import org.onosproject.event.AbstractListenerManager; 33 import org.onosproject.event.AbstractListenerManager;
...@@ -58,17 +61,22 @@ import org.onosproject.olt.AccessDeviceData; ...@@ -58,17 +61,22 @@ import org.onosproject.olt.AccessDeviceData;
58 import org.onosproject.olt.AccessDeviceEvent; 61 import org.onosproject.olt.AccessDeviceEvent;
59 import org.onosproject.olt.AccessDeviceListener; 62 import org.onosproject.olt.AccessDeviceListener;
60 import org.onosproject.olt.AccessDeviceService; 63 import org.onosproject.olt.AccessDeviceService;
64 +import org.osgi.service.component.ComponentContext;
61 import org.slf4j.Logger; 65 import org.slf4j.Logger;
62 66
67 +import java.util.Dictionary;
63 import java.util.List; 68 import java.util.List;
64 import java.util.Map; 69 import java.util.Map;
65 import java.util.Optional; 70 import java.util.Optional;
71 +import java.util.Properties;
66 import java.util.Set; 72 import java.util.Set;
67 import java.util.concurrent.CompletableFuture; 73 import java.util.concurrent.CompletableFuture;
68 import java.util.concurrent.ConcurrentHashMap; 74 import java.util.concurrent.ConcurrentHashMap;
69 import java.util.concurrent.ExecutorService; 75 import java.util.concurrent.ExecutorService;
70 import java.util.concurrent.Executors; 76 import java.util.concurrent.Executors;
71 77
78 +import static com.google.common.base.Strings.isNullOrEmpty;
79 +import static org.onlab.util.Tools.get;
72 import static org.onlab.util.Tools.groupedThreads; 80 import static org.onlab.util.Tools.groupedThreads;
73 import static org.slf4j.LoggerFactory.getLogger; 81 import static org.slf4j.LoggerFactory.getLogger;
74 82
...@@ -80,6 +88,9 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -80,6 +88,9 @@ import static org.slf4j.LoggerFactory.getLogger;
80 public class Olt 88 public class Olt
81 extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener> 89 extends AbstractListenerManager<AccessDeviceEvent, AccessDeviceListener>
82 implements AccessDeviceService { 90 implements AccessDeviceService {
91 +
92 + private static final short DEFAULT_VLAN = 0;
93 +
83 private final Logger log = getLogger(getClass()); 94 private final Logger log = getLogger(getClass());
84 95
85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 96 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -94,12 +105,18 @@ public class Olt ...@@ -94,12 +105,18 @@ public class Olt
94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 105 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
95 protected NetworkConfigRegistry networkConfig; 106 protected NetworkConfigRegistry networkConfig;
96 107
108 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
109 + protected ComponentConfigService componentConfigService;
110 +
111 +
112 + @Property(name = "defaultVlan", intValue = DEFAULT_VLAN,
113 + label = "Default VLAN RG<->ONU traffic")
114 + private int defaultVlan = DEFAULT_VLAN;
115 +
97 private final DeviceListener deviceListener = new InternalDeviceListener(); 116 private final DeviceListener deviceListener = new InternalDeviceListener();
98 117
99 private ApplicationId appId; 118 private ApplicationId appId;
100 119
101 - private static final VlanId DEFAULT_VLAN = VlanId.vlanId((short) 0);
102 -
103 private ExecutorService oltInstallers = Executors.newFixedThreadPool(4, 120 private ExecutorService oltInstallers = Executors.newFixedThreadPool(4,
104 groupedThreads("onos/olt-service", 121 groupedThreads("onos/olt-service",
105 "olt-installer-%d")); 122 "olt-installer-%d"));
...@@ -127,8 +144,10 @@ public class Olt ...@@ -127,8 +144,10 @@ public class Olt
127 144
128 145
129 @Activate 146 @Activate
130 - public void activate() { 147 + public void activate(ComponentContext context) {
148 + modified(context);
131 appId = coreService.registerApplication("org.onosproject.olt"); 149 appId = coreService.registerApplication("org.onosproject.olt");
150 + componentConfigService.registerProperties(getClass());
132 151
133 eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry); 152 eventDispatcher.addSink(AccessDeviceEvent.class, listenerRegistry);
134 153
...@@ -160,12 +179,25 @@ public class Olt ...@@ -160,12 +179,25 @@ public class Olt
160 179
161 @Deactivate 180 @Deactivate
162 public void deactivate() { 181 public void deactivate() {
182 + componentConfigService.unregisterProperties(getClass(), false);
163 deviceService.removeListener(deviceListener); 183 deviceService.removeListener(deviceListener);
164 networkConfig.removeListener(configListener); 184 networkConfig.removeListener(configListener);
165 networkConfig.unregisterConfigFactory(configFactory); 185 networkConfig.unregisterConfigFactory(configFactory);
166 log.info("Stopped"); 186 log.info("Stopped");
167 } 187 }
168 188
189 + @Modified
190 + public void modified(ComponentContext context) {
191 + Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties();
192 +
193 + try {
194 + String s = get(properties, "defaultVlan");
195 + defaultVlan = isNullOrEmpty(s) ? DEFAULT_VLAN : Integer.parseInt(s.trim());
196 + } catch (Exception e) {
197 + defaultVlan = DEFAULT_VLAN;
198 + }
199 + }
200 +
169 @Override 201 @Override
170 public void provisionSubscriber(ConnectPoint port, VlanId vlan) { 202 public void provisionSubscriber(ConnectPoint port, VlanId vlan) {
171 AccessDeviceData olt = oltData.get(port.deviceId()); 203 AccessDeviceData olt = oltData.get(port.deviceId());
...@@ -192,6 +224,11 @@ public class Olt ...@@ -192,6 +224,11 @@ public class Olt
192 224
193 } 225 }
194 226
227 + @Override
228 + public Map<DeviceId, AccessDeviceData> fetchOlts() {
229 + return Maps.newHashMap(oltData);
230 + }
231 +
195 private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink, 232 private void unprovisionSubscriber(DeviceId deviceId, PortNumber uplink,
196 PortNumber subscriberPort, VlanId deviceVlan) { 233 PortNumber subscriberPort, VlanId deviceVlan) {
197 234
...@@ -255,7 +292,7 @@ public class Olt ...@@ -255,7 +292,7 @@ public class Olt
255 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture(); 292 CompletableFuture<ObjectiveError> upFuture = new CompletableFuture();
256 293
257 TrafficSelector upstream = DefaultTrafficSelector.builder() 294 TrafficSelector upstream = DefaultTrafficSelector.builder()
258 - .matchVlanId(defaultVlan.orElse(DEFAULT_VLAN)) 295 + .matchVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan)))
259 .matchInPort(subscriberPort) 296 .matchInPort(subscriberPort)
260 .build(); 297 .build();
261 298
...@@ -275,7 +312,7 @@ public class Olt ...@@ -275,7 +312,7 @@ public class Olt
275 312
276 TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() 313 TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder()
277 .popVlan() 314 .popVlan()
278 - .setVlanId(defaultVlan.orElse(DEFAULT_VLAN)) 315 + .setVlanId(defaultVlan.orElse(VlanId.vlanId((short) this.defaultVlan)))
279 .setOutput(subscriberPort) 316 .setOutput(subscriberPort)
280 .build(); 317 .build();
281 318
...@@ -417,6 +454,7 @@ public class Olt ...@@ -417,6 +454,7 @@ public class Olt
417 post(new AccessDeviceEvent( 454 post(new AccessDeviceEvent(
418 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId, 455 AccessDeviceEvent.Type.DEVICE_CONNECTED, devId,
419 null, null)); 456 null, null));
457 + provisionDefaultFlows(devId);
420 break; 458 break;
421 case DEVICE_REMOVED: 459 case DEVICE_REMOVED:
422 post(new AccessDeviceEvent( 460 post(new AccessDeviceEvent(
...@@ -450,21 +488,29 @@ public class Olt ...@@ -450,21 +488,29 @@ public class Olt
450 488
451 case CONFIG_ADDED: 489 case CONFIG_ADDED:
452 case CONFIG_UPDATED: 490 case CONFIG_UPDATED:
453 - if (event.configClass().equals(CONFIG_CLASS)) { 491 +
454 AccessDeviceConfig config = 492 AccessDeviceConfig config =
455 networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS); 493 networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS);
456 if (config != null) { 494 if (config != null) {
457 oltData.put(config.getOlt().deviceId(), config.getOlt()); 495 oltData.put(config.getOlt().deviceId(), config.getOlt());
458 provisionDefaultFlows((DeviceId) event.subject()); 496 provisionDefaultFlows((DeviceId) event.subject());
459 } 497 }
460 - } 498 +
461 break; 499 break;
500 + case CONFIG_REGISTERED:
462 case CONFIG_UNREGISTERED: 501 case CONFIG_UNREGISTERED:
502 + break;
463 case CONFIG_REMOVED: 503 case CONFIG_REMOVED:
504 + oltData.remove(event.subject());
464 default: 505 default:
465 break; 506 break;
466 } 507 }
467 } 508 }
509 +
510 + @Override
511 + public boolean isRelevant(NetworkConfigEvent event) {
512 + return event.configClass().equals(CONFIG_CLASS);
513 + }
468 } 514 }
469 515
470 private void provisionDefaultFlows(DeviceId deviceId) { 516 private void provisionDefaultFlows(DeviceId deviceId) {
......
...@@ -30,6 +30,13 @@ ...@@ -30,6 +30,13 @@
30 <null/> 30 <null/>
31 </completers> 31 </completers>
32 </command> 32 </command>
33 + <command>
34 + <action class="org.onosproject.olt.cli.ShowOltCommand"/>
35 + <completers>
36 + <ref component-id="deviceIdCompleter"/>
37 + <null/>
38 + </completers>
39 + </command>
33 </command-bundle> 40 </command-bundle>
34 41
35 <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> 42 <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/>
......