Madan Jampani

Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next

1 +package org.onlab.onos.cli;
2 +
3 +import org.apache.karaf.shell.commands.Command;
4 +import org.onlab.onos.cluster.ClusterService;
5 +import org.onlab.onos.net.device.DeviceService;
6 +import org.onlab.onos.net.flow.FlowRuleService;
7 +import org.onlab.onos.net.host.HostService;
8 +import org.onlab.onos.net.intent.IntentService;
9 +import org.onlab.onos.net.link.LinkService;
10 +import org.onlab.onos.net.topology.Topology;
11 +import org.onlab.onos.net.topology.TopologyService;
12 +
13 +/**
14 + * Provides summary of ONOS model.
15 + */
16 +@Command(scope = "onos", name = "summary",
17 + description = "Provides summary of ONOS model")
18 +public class SummaryCommand extends AbstractShellCommand {
19 +
20 + @Override
21 + protected void execute() {
22 + TopologyService topologyService = get(TopologyService.class);
23 + Topology topology = topologyService.currentTopology();
24 + print("nodes=%d, devices=%d, links=%d, hosts=%d, clusters=%s, paths=%d, flows=%d, intents=%d",
25 + get(ClusterService.class).getNodes().size(),
26 + get(DeviceService.class).getDeviceCount(),
27 + get(LinkService.class).getLinkCount(),
28 + get(HostService.class).getHostCount(),
29 + topologyService.getClusters(topology).size(),
30 + topology.pathCount(),
31 + get(FlowRuleService.class).getFlowRuleCount(),
32 + get(IntentService.class).getIntentCount());
33 + }
34 +
35 +}
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
2 2
3 <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> 3 <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
4 <command> 4 <command>
5 + <action class="org.onlab.onos.cli.SummaryCommand"/>
6 + </command>
7 + <command>
5 <action class="org.onlab.onos.cli.NodesListCommand"/> 8 <action class="org.onlab.onos.cli.NodesListCommand"/>
6 </command> 9 </command>
7 <command> 10 <command>
......
...@@ -13,6 +13,13 @@ import org.onlab.onos.net.DeviceId; ...@@ -13,6 +13,13 @@ import org.onlab.onos.net.DeviceId;
13 public interface FlowRuleService { 13 public interface FlowRuleService {
14 14
15 /** 15 /**
16 + * Returns the number of flow rules in the system.
17 + *
18 + * @return flow rule count
19 + */
20 + int getFlowRuleCount();
21 +
22 + /**
16 * Returns the collection of flow entries applied on the specified device. 23 * Returns the collection of flow entries applied on the specified device.
17 * This will include flow rules which may not yet have been applied to 24 * This will include flow rules which may not yet have been applied to
18 * the device. 25 * the device.
...@@ -72,7 +79,4 @@ public interface FlowRuleService { ...@@ -72,7 +79,4 @@ public interface FlowRuleService {
72 * @param listener flow rule listener 79 * @param listener flow rule listener
73 */ 80 */
74 void removeListener(FlowRuleListener listener); 81 void removeListener(FlowRuleListener listener);
75 -
76 -
77 -
78 } 82 }
......
...@@ -10,7 +10,15 @@ import org.onlab.onos.store.Store; ...@@ -10,7 +10,15 @@ import org.onlab.onos.store.Store;
10 public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegate> { 10 public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegate> {
11 11
12 /** 12 /**
13 + * Returns the number of flow rule in the store.
14 + *
15 + * @return number of flow rules
16 + */
17 + int getFlowRuleCount();
18 +
19 + /**
13 * Returns the stored flow. 20 * Returns the stored flow.
21 + *
14 * @param rule the rule to look for 22 * @param rule the rule to look for
15 * @return a flow rule 23 * @return a flow rule
16 */ 24 */
...@@ -60,5 +68,4 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat ...@@ -60,5 +68,4 @@ public interface FlowRuleStore extends Store<FlowRuleEvent, FlowRuleStoreDelegat
60 * @return flow_removed event, or null if nothing removed 68 * @return flow_removed event, or null if nothing removed
61 */ 69 */
62 FlowRuleEvent removeFlowRule(FlowEntry rule); 70 FlowRuleEvent removeFlowRule(FlowEntry rule);
63 -
64 } 71 }
......
...@@ -40,14 +40,14 @@ import com.google.common.collect.Lists; ...@@ -40,14 +40,14 @@ import com.google.common.collect.Lists;
40 @Component(immediate = true) 40 @Component(immediate = true)
41 @Service 41 @Service
42 public class FlowRuleManager 42 public class FlowRuleManager
43 -extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService> 43 + extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService>
44 -implements FlowRuleService, FlowRuleProviderRegistry { 44 + implements FlowRuleService, FlowRuleProviderRegistry {
45 45
46 public static final String FLOW_RULE_NULL = "FlowRule cannot be null"; 46 public static final String FLOW_RULE_NULL = "FlowRule cannot be null";
47 private final Logger log = getLogger(getClass()); 47 private final Logger log = getLogger(getClass());
48 48
49 private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener> 49 private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener>
50 - listenerRegistry = new AbstractListenerRegistry<>(); 50 + listenerRegistry = new AbstractListenerRegistry<>();
51 51
52 private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate(); 52 private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate();
53 53
...@@ -75,6 +75,11 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -75,6 +75,11 @@ implements FlowRuleService, FlowRuleProviderRegistry {
75 } 75 }
76 76
77 @Override 77 @Override
78 + public int getFlowRuleCount() {
79 + return store.getFlowRuleCount();
80 + }
81 +
82 + @Override
78 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) { 83 public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
79 return store.getFlowEntries(deviceId); 84 return store.getFlowEntries(deviceId);
80 } 85 }
...@@ -98,15 +103,17 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -98,15 +103,17 @@ implements FlowRuleService, FlowRuleProviderRegistry {
98 for (int i = 0; i < flowRules.length; i++) { 103 for (int i = 0; i < flowRules.length; i++) {
99 f = flowRules[i]; 104 f = flowRules[i];
100 device = deviceService.getDevice(f.deviceId()); 105 device = deviceService.getDevice(f.deviceId());
101 - frp = getProvider(device.providerId());
102 store.deleteFlowRule(f); 106 store.deleteFlowRule(f);
103 - frp.removeFlowRule(f); 107 + if (device != null) {
108 + frp = getProvider(device.providerId());
109 + frp.removeFlowRule(f);
110 + }
104 } 111 }
105 } 112 }
106 113
107 @Override 114 @Override
108 public void removeFlowRulesById(ApplicationId id) { 115 public void removeFlowRulesById(ApplicationId id) {
109 - Iterable<FlowRule> rules = getFlowRulesById(id); 116 + Iterable<FlowRule> rules = getFlowRulesById(id);
110 FlowRuleProvider frp; 117 FlowRuleProvider frp;
111 Device device; 118 Device device;
112 119
...@@ -140,8 +147,8 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -140,8 +147,8 @@ implements FlowRuleService, FlowRuleProviderRegistry {
140 } 147 }
141 148
142 private class InternalFlowRuleProviderService 149 private class InternalFlowRuleProviderService
143 - extends AbstractProviderService<FlowRuleProvider> 150 + extends AbstractProviderService<FlowRuleProvider>
144 - implements FlowRuleProviderService { 151 + implements FlowRuleProviderService {
145 152
146 protected InternalFlowRuleProviderService(FlowRuleProvider provider) { 153 protected InternalFlowRuleProviderService(FlowRuleProvider provider) {
147 super(provider); 154 super(provider);
...@@ -160,16 +167,16 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -160,16 +167,16 @@ implements FlowRuleService, FlowRuleProviderRegistry {
160 FlowRuleProvider frp = getProvider(device.providerId()); 167 FlowRuleProvider frp = getProvider(device.providerId());
161 FlowRuleEvent event = null; 168 FlowRuleEvent event = null;
162 switch (stored.state()) { 169 switch (stored.state()) {
163 - case ADDED: 170 + case ADDED:
164 - case PENDING_ADD: 171 + case PENDING_ADD:
165 frp.applyFlowRule(stored); 172 frp.applyFlowRule(stored);
166 - break; 173 + break;
167 - case PENDING_REMOVE: 174 + case PENDING_REMOVE:
168 - case REMOVED: 175 + case REMOVED:
169 - event = store.removeFlowRule(stored); 176 + event = store.removeFlowRule(stored);
170 - break; 177 + break;
171 - default: 178 + default:
172 - break; 179 + break;
173 180
174 } 181 }
175 if (event != null) { 182 if (event != null) {
...@@ -186,17 +193,17 @@ implements FlowRuleService, FlowRuleProviderRegistry { ...@@ -186,17 +193,17 @@ implements FlowRuleService, FlowRuleProviderRegistry {
186 FlowRuleProvider frp = getProvider(device.providerId()); 193 FlowRuleProvider frp = getProvider(device.providerId());
187 FlowRuleEvent event = null; 194 FlowRuleEvent event = null;
188 switch (flowRule.state()) { 195 switch (flowRule.state()) {
189 - case PENDING_REMOVE: 196 + case PENDING_REMOVE:
190 - case REMOVED: 197 + case REMOVED:
191 - event = store.removeFlowRule(flowRule); 198 + event = store.removeFlowRule(flowRule);
192 - frp.removeFlowRule(flowRule); 199 + frp.removeFlowRule(flowRule);
193 - break; 200 + break;
194 - case ADDED: 201 + case ADDED:
195 - case PENDING_ADD: 202 + case PENDING_ADD:
196 - frp.applyFlowRule(flowRule); 203 + frp.applyFlowRule(flowRule);
197 - break; 204 + break;
198 - default: 205 + default:
199 - log.debug("Flow {} has not been installed.", flowRule); 206 + log.debug("Flow {} has not been installed.", flowRule);
200 } 207 }
201 208
202 if (event != null) { 209 if (event != null) {
......
...@@ -115,12 +115,7 @@ public class FlowTracker implements FlowTrackerService { ...@@ -115,12 +115,7 @@ public class FlowTracker implements FlowTrackerService {
115 for (Event reason : event.reasons()) { 115 for (Event reason : event.reasons()) {
116 if (reason instanceof LinkEvent) { 116 if (reason instanceof LinkEvent) {
117 LinkEvent linkEvent = (LinkEvent) reason; 117 LinkEvent linkEvent = (LinkEvent) reason;
118 - if (linkEvent.type() == LinkEvent.Type.LINK_ADDED || 118 + delegate.bumpIntents(intentsByLink.get(new LinkKey(linkEvent.subject())));
119 - linkEvent.type() == LinkEvent.Type.LINK_UPDATED) {
120 - delegate.bumpIntents(intentsByLink.get(new LinkKey(linkEvent.subject())));
121 - } else if (linkEvent.type() == LinkEvent.Type.LINK_REMOVED) {
122 - delegate.failIntents(intentsByLink.get(new LinkKey(linkEvent.subject())));
123 - }
124 } 119 }
125 } 120 }
126 } 121 }
......
...@@ -359,13 +359,5 @@ public class IntentManager ...@@ -359,13 +359,5 @@ public class IntentManager
359 } 359 }
360 } 360 }
361 361
362 - @Override
363 - public void failIntents(Iterable<IntentId> intentIds) {
364 - for (IntentId intentId : intentIds) {
365 - Intent intent = getIntent(intentId);
366 - uninstallIntent(intent);
367 - compileIntent(intent);
368 - }
369 - }
370 } 362 }
371 } 363 }
......
...@@ -15,12 +15,4 @@ public interface TopologyChangeDelegate { ...@@ -15,12 +15,4 @@ public interface TopologyChangeDelegate {
15 */ 15 */
16 void bumpIntents(Iterable<IntentId> intentIds); 16 void bumpIntents(Iterable<IntentId> intentIds);
17 17
18 - /**
19 - * Notifies that topology has changed in such a way that the specified
20 - * intents should be marked failed and then recompiled.
21 - *
22 - * @param intentIds intents that should be failed and recompiled
23 - */
24 - void failIntents(Iterable<IntentId> intentIds);
25 -
26 } 18 }
......
...@@ -58,6 +58,11 @@ public class DistributedFlowRuleStore ...@@ -58,6 +58,11 @@ public class DistributedFlowRuleStore
58 58
59 59
60 @Override 60 @Override
61 + public int getFlowRuleCount() {
62 + return flowEntries.size();
63 + }
64 +
65 + @Override
61 public synchronized FlowEntry getFlowEntry(FlowRule rule) { 66 public synchronized FlowEntry getFlowEntry(FlowRule rule) {
62 for (FlowEntry f : flowEntries.get(rule.deviceId())) { 67 for (FlowEntry f : flowEntries.get(rule.deviceId())) {
63 if (f.equals(rule)) { 68 if (f.equals(rule)) {
......
...@@ -58,6 +58,11 @@ public class DistributedFlowRuleStore ...@@ -58,6 +58,11 @@ public class DistributedFlowRuleStore
58 58
59 59
60 @Override 60 @Override
61 + public int getFlowRuleCount() {
62 + return flowEntries.size();
63 + }
64 +
65 + @Override
61 public synchronized FlowEntry getFlowEntry(FlowRule rule) { 66 public synchronized FlowEntry getFlowEntry(FlowRule rule) {
62 for (FlowEntry f : flowEntries.get(rule.deviceId())) { 67 for (FlowEntry f : flowEntries.get(rule.deviceId())) {
63 if (f.equals(rule)) { 68 if (f.equals(rule)) {
......
...@@ -57,6 +57,11 @@ public class SimpleFlowRuleStore ...@@ -57,6 +57,11 @@ public class SimpleFlowRuleStore
57 57
58 58
59 @Override 59 @Override
60 + public int getFlowRuleCount() {
61 + return flowEntries.size();
62 + }
63 +
64 + @Override
60 public synchronized FlowEntry getFlowEntry(FlowRule rule) { 65 public synchronized FlowEntry getFlowEntry(FlowRule rule) {
61 for (FlowEntry f : flowEntries.get(rule.deviceId())) { 66 for (FlowEntry f : flowEntries.get(rule.deviceId())) {
62 if (f.equals(rule)) { 67 if (f.equals(rule)) {
......