Saurav Das
Committed by Yuta HIGUCHI

CORD-613 Adding ability to administratively enable or disable a port via CLI.

Currently uses the OpenFlow device provider to change portState.
Also fixes a bug in PortNumberCompleter.
Adds completion options to portstats for deviceId and portNumber.

Change-Id: Idcce775fe8bc5484fdd0e630bcb5026b85125478
Showing 21 changed files with 330 additions and 21 deletions
...@@ -22,6 +22,7 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -22,6 +22,7 @@ import org.onosproject.net.DefaultAnnotations;
22 import org.onosproject.net.Device; 22 import org.onosproject.net.Device;
23 import org.onosproject.net.DeviceId; 23 import org.onosproject.net.DeviceId;
24 import org.onosproject.net.MastershipRole; 24 import org.onosproject.net.MastershipRole;
25 +import org.onosproject.net.PortNumber;
25 import org.onosproject.net.device.DefaultDeviceDescription; 26 import org.onosproject.net.device.DefaultDeviceDescription;
26 import org.onosproject.net.device.DeviceDescription; 27 import org.onosproject.net.device.DeviceDescription;
27 import org.onosproject.net.device.DeviceProvider; 28 import org.onosproject.net.device.DeviceProvider;
...@@ -100,5 +101,10 @@ public class AnnotateDeviceCommand extends AbstractShellCommand { ...@@ -100,5 +101,10 @@ public class AnnotateDeviceCommand extends AbstractShellCommand {
100 public boolean isReachable(DeviceId deviceId) { 101 public boolean isReachable(DeviceId deviceId) {
101 return false; 102 return false;
102 } 103 }
104 +
105 + @Override
106 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
107 + boolean enable) {
108 + }
103 } 109 }
104 } 110 }
......
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.cli.net;
17 +
18 +import org.apache.karaf.shell.commands.Argument;
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.net.Device;
22 +import org.onosproject.net.DeviceId;
23 +import org.onosproject.net.Port;
24 +import org.onosproject.net.PortNumber;
25 +import org.onosproject.net.device.DeviceAdminService;
26 +import org.onosproject.net.device.DeviceService;
27 +
28 +/**
29 + * Administratively enables or disabled a port on a device.
30 + */
31 +@Command(scope = "onos", name = "portstate",
32 + description = "Administratively enables or disabled a port on a device")
33 +public class DevicePortStateCommand extends AbstractShellCommand {
34 + @Argument(index = 0, name = "uri", description = "Device ID",
35 + required = true, multiValued = false)
36 + String uri = null;
37 +
38 + @Argument(index = 1, name = "portNumber", description = "Port Number",
39 + required = true, multiValued = false)
40 + Integer portNumber = null;
41 +
42 + @Argument(index = 2, name = "portState", description = "Desired State",
43 + required = true, multiValued = false)
44 + String portState = null;
45 +
46 + @Override
47 + protected void execute() {
48 + DeviceService deviceService = get(DeviceService.class);
49 + DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
50 + Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
51 + if (dev == null) {
52 + print(" %s", "Device does not exist");
53 + return;
54 + }
55 + PortNumber pnum = PortNumber.portNumber(portNumber);
56 + Port p = deviceService.getPort(dev.id(), pnum);
57 + if (p == null) {
58 + print(" %s", "Port does not exist");
59 + return;
60 + }
61 + if (portState.equals("enable")) {
62 + deviceAdminService.changePortState(dev.id(), pnum, true);
63 + } else if (portState.equals("disable")) {
64 + deviceAdminService.changePortState(dev.id(), pnum, false);
65 + } else {
66 + print(" %s", "State must be enable or disable");
67 + }
68 + }
69 +}
...@@ -50,6 +50,10 @@ public class DevicePortStatsCommand extends DevicesListCommand { ...@@ -50,6 +50,10 @@ public class DevicePortStatsCommand extends DevicesListCommand {
50 required = false, multiValued = false) 50 required = false, multiValued = false)
51 String uri = null; 51 String uri = null;
52 52
53 + @Argument(index = 1, name = "portNumber", description = "Port Number",
54 + required = false, multiValued = false)
55 + Integer portNumber = null;
56 +
53 private static final String FORMAT = 57 private static final String FORMAT =
54 " port=%s, pktRx=%s, pktTx=%s, bytesRx=%s, bytesTx=%s, pktRxDrp=%s, pktTxDrp=%s, Dur=%s"; 58 " port=%s, pktRx=%s, pktTx=%s, bytesRx=%s, bytesTx=%s, pktRxDrp=%s, pktTxDrp=%s, Dur=%s";
55 59
...@@ -94,6 +98,9 @@ public class DevicePortStatsCommand extends DevicesListCommand { ...@@ -94,6 +98,9 @@ public class DevicePortStatsCommand extends DevicesListCommand {
94 private void printPortStats(DeviceId deviceId, Iterable<PortStatistics> portStats) { 98 private void printPortStats(DeviceId deviceId, Iterable<PortStatistics> portStats) {
95 print("deviceId=%s", deviceId); 99 print("deviceId=%s", deviceId);
96 for (PortStatistics stat : sortByPort(portStats)) { 100 for (PortStatistics stat : sortByPort(portStats)) {
101 + if (portNumber != null && stat.port() != portNumber) {
102 + continue;
103 + }
97 print(FORMAT, stat.port(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(), 104 print(FORMAT, stat.port(), stat.packetsReceived(), stat.packetsSent(), stat.bytesReceived(),
98 stat.bytesSent(), stat.packetsRxDropped(), stat.packetsTxDropped(), stat.durationSec()); 105 stat.bytesSent(), stat.packetsRxDropped(), stat.packetsTxDropped(), stat.durationSec());
99 } 106 }
...@@ -109,6 +116,9 @@ public class DevicePortStatsCommand extends DevicesListCommand { ...@@ -109,6 +116,9 @@ public class DevicePortStatsCommand extends DevicesListCommand {
109 + " rateRx=%s, rateTx=%s, pktRxDrp=%s, pktTxDrp=%s, interval=%s"; 116 + " rateRx=%s, rateTx=%s, pktRxDrp=%s, pktTxDrp=%s, interval=%s";
110 print("deviceId=%s", deviceId); 117 print("deviceId=%s", deviceId);
111 for (PortStatistics stat : sortByPort(portStats)) { 118 for (PortStatistics stat : sortByPort(portStats)) {
119 + if (portNumber != null && stat.port() != portNumber) {
120 + continue;
121 + }
112 float duration = ((float) stat.durationSec()) + 122 float duration = ((float) stat.durationSec()) +
113 (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1)); 123 (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
114 float rateRx = stat.bytesReceived() * 8 / duration; 124 float rateRx = stat.bytesReceived() * 8 / duration;
...@@ -142,21 +152,24 @@ public class DevicePortStatsCommand extends DevicesListCommand { ...@@ -142,21 +152,24 @@ public class DevicePortStatsCommand extends DevicesListCommand {
142 print("|---------------------------------------------------------------------------------------------------|"); 152 print("|---------------------------------------------------------------------------------------------------|");
143 153
144 for (PortStatistics stat : sortByPort(portStats)) { 154 for (PortStatistics stat : sortByPort(portStats)) {
145 - float duration = ((float) stat.durationSec()) + 155 + if (portNumber != null && stat.port() != portNumber) {
146 - (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1)); 156 + continue;
147 - float rateRx = stat.bytesReceived() * 8 / duration;
148 - float rateTx = stat.bytesSent() * 8 / duration;
149 - print(formatDeltaTable, stat.port(),
150 - humanReadable(stat.packetsReceived()),
151 - humanReadable(stat.bytesReceived()),
152 - humanReadableBps(rateRx),
153 - humanReadable(stat.packetsRxDropped()),
154 - humanReadable(stat.packetsSent()),
155 - humanReadable(stat.bytesSent()),
156 - humanReadableBps(rateTx),
157 - humanReadable(stat.packetsTxDropped()),
158 - String.format("%.3f", duration));
159 } 157 }
158 + float duration = ((float) stat.durationSec()) +
159 + (((float) stat.durationNano()) / TimeUnit.SECONDS.toNanos(1));
160 + float rateRx = stat.bytesReceived() * 8 / duration;
161 + float rateTx = stat.bytesSent() * 8 / duration;
162 + print(formatDeltaTable, stat.port(),
163 + humanReadable(stat.packetsReceived()),
164 + humanReadable(stat.bytesReceived()),
165 + humanReadableBps(rateRx),
166 + humanReadable(stat.packetsRxDropped()),
167 + humanReadable(stat.packetsSent()),
168 + humanReadable(stat.bytesSent()),
169 + humanReadableBps(rateTx),
170 + humanReadable(stat.packetsTxDropped()),
171 + String.format("%.3f", duration));
172 + }
160 print("+---------------------------------------------------------------------------------------------------+"); 173 print("+---------------------------------------------------------------------------------------------------+");
161 } 174 }
162 175
......
...@@ -15,15 +15,16 @@ ...@@ -15,15 +15,16 @@
15 */ 15 */
16 package org.onosproject.cli.net; 16 package org.onosproject.cli.net;
17 17
18 -import static com.google.common.base.Preconditions.checkArgument;
19 import static org.onlab.osgi.DefaultServiceDirectory.getService; 18 import static org.onlab.osgi.DefaultServiceDirectory.getService;
20 19
20 +import java.util.Collections;
21 import java.util.List; 21 import java.util.List;
22 import java.util.stream.Collectors; 22 import java.util.stream.Collectors;
23 import java.util.stream.StreamSupport; 23 import java.util.stream.StreamSupport;
24 24
25 import org.apache.karaf.shell.console.completer.ArgumentCompleter.ArgumentList; 25 import org.apache.karaf.shell.console.completer.ArgumentCompleter.ArgumentList;
26 import org.onosproject.cli.AbstractChoicesCompleter; 26 import org.onosproject.cli.AbstractChoicesCompleter;
27 +import org.onosproject.net.Device;
27 import org.onosproject.net.DeviceId; 28 import org.onosproject.net.DeviceId;
28 import org.onosproject.net.device.DeviceService; 29 import org.onosproject.net.device.DeviceService;
29 30
...@@ -37,13 +38,22 @@ public class PortNumberCompleter extends AbstractChoicesCompleter { ...@@ -37,13 +38,22 @@ public class PortNumberCompleter extends AbstractChoicesCompleter {
37 @Override 38 @Override
38 protected List<String> choices() { 39 protected List<String> choices() {
39 ArgumentList args = getArgumentList(); 40 ArgumentList args = getArgumentList();
40 - checkArgument(args.getCursorArgumentIndex() >= 1, 41 + //parse argument list for deviceId
41 - "Expects DeviceId as previous argument");
42 -
43 - String deviceIdStr = args.getArguments()[args.getCursorArgumentIndex() - 1];
44 - DeviceId deviceId = DeviceId.deviceId(deviceIdStr);
45 -
46 DeviceService deviceService = getService(DeviceService.class); 42 DeviceService deviceService = getService(DeviceService.class);
43 + Device dev = null;
44 + for (String str : args.getArguments()) {
45 + if (str.contains(":")) {
46 + dev = deviceService.getDevice(DeviceId.deviceId(str));
47 + if (dev != null) {
48 + break;
49 + }
50 + }
51 + }
52 + if (dev == null) {
53 + return Collections.singletonList("Missing device");
54 + }
55 + DeviceId deviceId = dev.id();
56 +
47 return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false) 57 return StreamSupport.stream(deviceService.getPorts(deviceId).spliterator(), false)
48 .map(port -> port.number().toString()) 58 .map(port -> port.number().toString())
49 .collect(Collectors.toList()); 59 .collect(Collectors.toList());
......
1 +/*
2 + * Copyright 2016 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 +package org.onosproject.cli.net;
17 +
18 +import java.util.List;
19 +
20 +import org.onosproject.cli.AbstractChoicesCompleter;
21 +
22 +import com.google.common.collect.ImmutableList;
23 +
24 +/**
25 + * PortState completer.
26 + *
27 + * Assumes argument right before the one being completed is PortNumber.
28 + */
29 +public class PortStateCompleter extends AbstractChoicesCompleter {
30 +
31 + @Override
32 + protected List<String> choices() {
33 + return ImmutableList.of("enable", "disable");
34 + }
35 +}
...@@ -123,6 +123,15 @@ ...@@ -123,6 +123,15 @@
123 </completers> 123 </completers>
124 </command> 124 </command>
125 <command> 125 <command>
126 + <action class="org.onosproject.cli.net.DevicePortStateCommand"/>
127 + <completers>
128 + <ref component-id="deviceIdCompleter"/>
129 + <ref component-id="portNumberCompleter"/>
130 + <ref component-id="portStateCompleter"/>
131 + <null/>
132 + </completers>
133 + </command>
134 + <command>
126 <action class="org.onosproject.cli.net.DeviceControllersCommand"/> 135 <action class="org.onosproject.cli.net.DeviceControllersCommand"/>
127 <completers> 136 <completers>
128 <ref component-id="deviceIdCompleter"/> 137 <ref component-id="deviceIdCompleter"/>
...@@ -433,6 +442,11 @@ ...@@ -433,6 +442,11 @@
433 442
434 <command> 443 <command>
435 <action class="org.onosproject.cli.net.DevicePortStatsCommand"/> 444 <action class="org.onosproject.cli.net.DevicePortStatsCommand"/>
445 + <completers>
446 + <ref component-id="deviceIdCompleter"/>
447 + <ref component-id="portNumberCompleter"/>
448 + <null/>
449 + </completers>
436 </command> 450 </command>
437 451
438 <command> 452 <command>
...@@ -650,6 +664,7 @@ ...@@ -650,6 +664,7 @@
650 <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/> 664 <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/>
651 <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> 665 <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/>
652 <bean id="portNumberCompleter" class="org.onosproject.cli.net.PortNumberCompleter"/> 666 <bean id="portNumberCompleter" class="org.onosproject.cli.net.PortNumberCompleter"/>
667 + <bean id="portStateCompleter" class="org.onosproject.cli.net.PortStateCompleter"/>
653 <bean id="clusterIdCompleter" class="org.onosproject.cli.net.ClusterIdCompleter"/> 668 <bean id="clusterIdCompleter" class="org.onosproject.cli.net.ClusterIdCompleter"/>
654 <bean id="roleCompleter" class="org.onosproject.cli.net.RoleCompleter"/> 669 <bean id="roleCompleter" class="org.onosproject.cli.net.RoleCompleter"/>
655 <bean id="hostIdCompleter" class="org.onosproject.cli.net.HostIdCompleter"/> 670 <bean id="hostIdCompleter" class="org.onosproject.cli.net.HostIdCompleter"/>
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.device; 16 package org.onosproject.net.device;
17 17
18 import org.onosproject.net.DeviceId; 18 import org.onosproject.net.DeviceId;
19 +import org.onosproject.net.PortNumber;
19 20
20 /** 21 /**
21 * Service for administering the inventory of infrastructure devices. 22 * Service for administering the inventory of infrastructure devices.
...@@ -31,4 +32,13 @@ public interface DeviceAdminService extends DeviceService { ...@@ -31,4 +32,13 @@ public interface DeviceAdminService extends DeviceService {
31 32
32 // TODO: add ability to administratively suspend/resume device 33 // TODO: add ability to administratively suspend/resume device
33 34
35 +
36 + /**
37 + * Administratively enables or disables a port on a device.
38 + *
39 + * @param deviceId device identifier
40 + * @param portNumber port identifier
41 + * @param enable true if port is to be enabled, false to disable
42 + */
43 + void changePortState(DeviceId deviceId, PortNumber portNumber, boolean enable);
34 } 44 }
......
...@@ -17,6 +17,7 @@ package org.onosproject.net.device; ...@@ -17,6 +17,7 @@ package org.onosproject.net.device;
17 17
18 import org.onosproject.net.DeviceId; 18 import org.onosproject.net.DeviceId;
19 import org.onosproject.net.MastershipRole; 19 import org.onosproject.net.MastershipRole;
20 +import org.onosproject.net.PortNumber;
20 import org.onosproject.net.provider.Provider; 21 import org.onosproject.net.provider.Provider;
21 22
22 /** 23 /**
...@@ -54,4 +55,14 @@ public interface DeviceProvider extends Provider { ...@@ -54,4 +55,14 @@ public interface DeviceProvider extends Provider {
54 * @return true if reachable, false otherwise 55 * @return true if reachable, false otherwise
55 */ 56 */
56 boolean isReachable(DeviceId deviceId); 57 boolean isReachable(DeviceId deviceId);
58 +
59 + /**
60 + * Administratively enables or disables a port.
61 + *
62 + * @param deviceId device identifier
63 + * @param portNumber device identifier
64 + * @param enable true if port is to be enabled, false to disable
65 + */
66 + void changePortState(DeviceId deviceId, PortNumber portNumber,
67 + boolean enable);
57 } 68 }
......
...@@ -248,6 +248,22 @@ public class DeviceManager ...@@ -248,6 +248,22 @@ public class DeviceManager
248 } 248 }
249 249
250 @Override 250 @Override
251 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
252 + boolean enable) {
253 + checkNotNull(deviceId, DEVICE_ID_NULL);
254 + checkNotNull(deviceId, PORT_NUMBER_NULL);
255 + DeviceProvider provider = getProvider(deviceId);
256 + if (provider != null) {
257 + log.warn("Port {} on device {} being administratively brought {}",
258 + portNumber, deviceId,
259 + (enable) ? "UP" : "DOWN");
260 + provider.changePortState(deviceId, portNumber, enable);
261 + } else {
262 + log.warn("Provider not found for {}", deviceId);
263 + }
264 + }
265 +
266 + @Override
251 protected DeviceProviderService createProviderService( 267 protected DeviceProviderService createProviderService(
252 DeviceProvider provider) { 268 DeviceProvider provider) {
253 return new InternalDeviceProviderService(provider); 269 return new InternalDeviceProviderService(provider);
...@@ -340,6 +356,7 @@ public class DeviceManager ...@@ -340,6 +356,7 @@ public class DeviceManager
340 log.trace("event: {} {}", event.type(), event); 356 log.trace("event: {} {}", event.type(), event);
341 post(event); 357 post(event);
342 } 358 }
359 +
343 } 360 }
344 361
345 @Override 362 @Override
...@@ -790,4 +807,5 @@ public class DeviceManager ...@@ -790,4 +807,5 @@ public class DeviceManager
790 } 807 }
791 } 808 }
792 } 809 }
810 +
793 } 811 }
......
...@@ -274,6 +274,11 @@ public class DeviceManagerTest { ...@@ -274,6 +274,11 @@ public class DeviceManagerTest {
274 public boolean isReachable(DeviceId device) { 274 public boolean isReachable(DeviceId device) {
275 return false; 275 return false;
276 } 276 }
277 +
278 + @Override
279 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
280 + boolean enable) {
281 + }
277 } 282 }
278 283
279 private static class TestListener implements DeviceListener { 284 private static class TestListener implements DeviceListener {
......
...@@ -51,6 +51,7 @@ import org.onosproject.grpc.DeviceProviderRegistryRpcGrpc.DeviceProviderRegistry ...@@ -51,6 +51,7 @@ import org.onosproject.grpc.DeviceProviderRegistryRpcGrpc.DeviceProviderRegistry
51 import org.onosproject.grpc.LinkProviderServiceRpcGrpc; 51 import org.onosproject.grpc.LinkProviderServiceRpcGrpc;
52 import org.onosproject.net.DeviceId; 52 import org.onosproject.net.DeviceId;
53 import org.onosproject.net.MastershipRole; 53 import org.onosproject.net.MastershipRole;
54 +import org.onosproject.net.PortNumber;
54 import org.onosproject.net.device.DeviceProvider; 55 import org.onosproject.net.device.DeviceProvider;
55 import org.onosproject.net.device.DeviceProviderRegistry; 56 import org.onosproject.net.device.DeviceProviderRegistry;
56 import org.onosproject.net.device.DeviceProviderService; 57 import org.onosproject.net.device.DeviceProviderService;
...@@ -435,5 +436,12 @@ public class GrpcRemoteServiceServer { ...@@ -435,5 +436,12 @@ public class GrpcRemoteServiceServer {
435 return checkNotNull(providerId, "not initialized yet"); 436 return checkNotNull(providerId, "not initialized yet");
436 } 437 }
437 438
439 + @Override
440 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
441 + boolean enable) {
442 + // TODO if required
443 +
444 + }
445 +
438 } 446 }
439 } 447 }
......
...@@ -341,6 +341,10 @@ public class GrpcRemoteServiceTest { ...@@ -341,6 +341,10 @@ public class GrpcRemoteServiceTest {
341 DeviceId isReachableDid; 341 DeviceId isReachableDid;
342 boolean isReachableReply = false; 342 boolean isReachableReply = false;
343 343
344 + final CountDownLatch portStateChanged = new CountDownLatch(1);
345 + DeviceId portStateChangedDid;
346 + PortNumber portStateChangedPort;
347 +
344 @Override 348 @Override
345 public ProviderId id() { 349 public ProviderId id() {
346 return PID; 350 return PID;
...@@ -369,6 +373,17 @@ public class GrpcRemoteServiceTest { ...@@ -369,6 +373,17 @@ public class GrpcRemoteServiceTest {
369 return isReachableReply; 373 return isReachableReply;
370 } 374 }
371 375
376 + @Override
377 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
378 + boolean enable) {
379 + log.info("portState change to {} on ({},{}) on Client called", enable,
380 + deviceId, portNumber);
381 + portStateChangedDid = deviceId;
382 + portStateChangedPort = portNumber;
383 + portStateChanged.countDown();
384 +
385 + }
386 +
372 } 387 }
373 388
374 class NoOpRemoteServiceProviderRegistry 389 class NoOpRemoteServiceProviderRegistry
......
...@@ -29,6 +29,7 @@ import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4; ...@@ -29,6 +29,7 @@ import org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4;
29 import org.onosproject.net.Device; 29 import org.onosproject.net.Device;
30 import org.onosproject.net.DeviceId; 30 import org.onosproject.net.DeviceId;
31 import org.onosproject.net.MastershipRole; 31 import org.onosproject.net.MastershipRole;
32 +import org.onosproject.net.PortNumber;
32 import org.onosproject.net.device.DefaultDeviceDescription; 33 import org.onosproject.net.device.DefaultDeviceDescription;
33 import org.onosproject.net.device.DeviceDescription; 34 import org.onosproject.net.device.DeviceDescription;
34 import org.onosproject.net.device.DeviceProvider; 35 import org.onosproject.net.device.DeviceProvider;
...@@ -122,4 +123,9 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi ...@@ -122,4 +123,9 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi
122 // TODO Auto-generated method stub 123 // TODO Auto-generated method stub
123 return true; 124 return true;
124 } 125 }
126 +
127 + @Override
128 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
129 + boolean enable) {
130 + }
125 } 131 }
......
...@@ -34,6 +34,7 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -34,6 +34,7 @@ import org.onosproject.net.DefaultAnnotations;
34 import org.onosproject.net.Device; 34 import org.onosproject.net.Device;
35 import org.onosproject.net.DeviceId; 35 import org.onosproject.net.DeviceId;
36 import org.onosproject.net.MastershipRole; 36 import org.onosproject.net.MastershipRole;
37 +import org.onosproject.net.PortNumber;
37 import org.onosproject.net.SparseAnnotations; 38 import org.onosproject.net.SparseAnnotations;
38 import org.onosproject.net.behaviour.PortDiscovery; 39 import org.onosproject.net.behaviour.PortDiscovery;
39 import org.onosproject.net.config.ConfigFactory; 40 import org.onosproject.net.config.ConfigFactory;
...@@ -250,6 +251,12 @@ public class NetconfDeviceProvider extends AbstractProvider ...@@ -250,6 +251,12 @@ public class NetconfDeviceProvider extends AbstractProvider
250 } 251 }
251 } 252 }
252 253
254 + @Override
255 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
256 + boolean enable) {
257 + // TODO if required
258 + }
259 +
253 private class InnerNetconfDeviceListener implements NetconfDeviceListener { 260 private class InnerNetconfDeviceListener implements NetconfDeviceListener {
254 261
255 262
......
...@@ -32,6 +32,7 @@ import org.onosproject.net.ConnectPoint; ...@@ -32,6 +32,7 @@ import org.onosproject.net.ConnectPoint;
32 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
33 import org.onosproject.net.Host; 33 import org.onosproject.net.Host;
34 import org.onosproject.net.MastershipRole; 34 import org.onosproject.net.MastershipRole;
35 +import org.onosproject.net.PortNumber;
35 import org.onosproject.net.device.DeviceAdminService; 36 import org.onosproject.net.device.DeviceAdminService;
36 import org.onosproject.net.device.DeviceProvider; 37 import org.onosproject.net.device.DeviceProvider;
37 import org.onosproject.net.device.DeviceProviderRegistry; 38 import org.onosproject.net.device.DeviceProviderRegistry;
...@@ -431,6 +432,12 @@ public class NullProviders { ...@@ -431,6 +432,12 @@ public class NullProviders {
431 @Override 432 @Override
432 public void triggerProbe(DeviceId deviceId) { 433 public void triggerProbe(DeviceId deviceId) {
433 } 434 }
435 +
436 + @Override
437 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
438 + boolean enable) {
439 + // TODO maybe required
440 + }
434 } 441 }
435 442
436 // Host provider facade. 443 // Host provider facade.
......
...@@ -19,6 +19,7 @@ import com.google.common.base.Strings; ...@@ -19,6 +19,7 @@ import com.google.common.base.Strings;
19 import com.google.common.collect.Lists; 19 import com.google.common.collect.Lists;
20 import com.google.common.collect.Maps; 20 import com.google.common.collect.Maps;
21 import com.google.common.collect.Sets; 21 import com.google.common.collect.Sets;
22 +
22 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 25 import org.apache.felix.scr.annotations.Deactivate;
...@@ -71,6 +72,8 @@ import org.osgi.service.component.ComponentContext; ...@@ -71,6 +72,8 @@ import org.osgi.service.component.ComponentContext;
71 import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp; 72 import org.projectfloodlight.openflow.protocol.OFCalientPortDescProp;
72 import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical; 73 import org.projectfloodlight.openflow.protocol.OFCalientPortDescPropOptical;
73 import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry; 74 import org.projectfloodlight.openflow.protocol.OFCalientPortDescStatsEntry;
75 +import org.projectfloodlight.openflow.protocol.OFErrorMsg;
76 +import org.projectfloodlight.openflow.protocol.OFErrorType;
74 import org.projectfloodlight.openflow.protocol.OFExpPort; 77 import org.projectfloodlight.openflow.protocol.OFExpPort;
75 import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport; 78 import org.projectfloodlight.openflow.protocol.OFExpPortDescPropOpticalTransport;
76 import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry; 79 import org.projectfloodlight.openflow.protocol.OFExpPortOpticalTransportLayerEntry;
...@@ -81,6 +84,7 @@ import org.projectfloodlight.openflow.protocol.OFPortConfig; ...@@ -81,6 +84,7 @@ import org.projectfloodlight.openflow.protocol.OFPortConfig;
81 import org.projectfloodlight.openflow.protocol.OFPortDesc; 84 import org.projectfloodlight.openflow.protocol.OFPortDesc;
82 import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport; 85 import org.projectfloodlight.openflow.protocol.OFPortDescPropOpticalTransport;
83 import org.projectfloodlight.openflow.protocol.OFPortFeatures; 86 import org.projectfloodlight.openflow.protocol.OFPortFeatures;
87 +import org.projectfloodlight.openflow.protocol.OFPortMod;
84 import org.projectfloodlight.openflow.protocol.OFPortOptical; 88 import org.projectfloodlight.openflow.protocol.OFPortOptical;
85 import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass; 89 import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportLayerClass;
86 import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType; 90 import org.projectfloodlight.openflow.protocol.OFPortOpticalTransportSignalType;
...@@ -93,6 +97,7 @@ import org.projectfloodlight.openflow.protocol.OFStatsReply; ...@@ -93,6 +97,7 @@ import org.projectfloodlight.openflow.protocol.OFStatsReply;
93 import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; 97 import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
94 import org.projectfloodlight.openflow.protocol.OFStatsType; 98 import org.projectfloodlight.openflow.protocol.OFStatsType;
95 import org.projectfloodlight.openflow.protocol.OFVersion; 99 import org.projectfloodlight.openflow.protocol.OFVersion;
100 +import org.projectfloodlight.openflow.types.OFPort;
96 import org.projectfloodlight.openflow.types.PortSpeed; 101 import org.projectfloodlight.openflow.types.PortSpeed;
97 import org.slf4j.Logger; 102 import org.slf4j.Logger;
98 103
...@@ -268,6 +273,34 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -268,6 +273,34 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
268 LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId); 273 LOG.debug("Accepting mastership role change to {} for device {}", newRole, deviceId);
269 } 274 }
270 275
276 + @Override
277 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
278 + boolean enable) {
279 + final Dpid dpid = dpid(deviceId.uri());
280 + OpenFlowSwitch sw = controller.getSwitch(dpid);
281 + if (sw == null || !sw.isConnected()) {
282 + LOG.error("Failed to change portState on device {}", deviceId);
283 + return;
284 + }
285 + OFPortMod.Builder pmb = sw.factory().buildPortMod();
286 + OFPort port = OFPort.of((int) portNumber.toLong());
287 + pmb.setPortNo(port);
288 + if (enable) {
289 + pmb.setConfig(0x0); // port_down bit 0
290 + } else {
291 + pmb.setConfig(0x1); // port_down bit 1
292 + }
293 + pmb.setMask(0x1);
294 + pmb.setAdvertise(0x0);
295 + for (OFPortDesc pd : sw.getPorts()) {
296 + if (pd.getPortNo().equals(port)) {
297 + pmb.setHwAddr(pd.getHwAddr());
298 + break;
299 + }
300 + }
301 + sw.sendMsg(Collections.singletonList(pmb.build()));
302 + }
303 +
271 private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) { 304 private void pushPortMetrics(Dpid dpid, List<OFPortStatsEntry> portStatsEntries) {
272 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid)); 305 DeviceId deviceId = DeviceId.deviceId(Dpid.uri(dpid));
273 Collection<PortStatistics> stats = buildPortStatistics(deviceId, portStatsEntries); 306 Collection<PortStatistics> stats = buildPortStatistics(deviceId, portStatsEntries);
...@@ -756,9 +789,15 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -756,9 +789,15 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
756 } 789 }
757 } 790 }
758 break; 791 break;
792 + case ERROR:
793 + if (((OFErrorMsg) msg).getErrType() == OFErrorType.PORT_MOD_FAILED) {
794 + LOG.error("port mod failed");
795 + }
759 default: 796 default:
760 break; 797 break;
761 } 798 }
762 } 799 }
763 } 800 }
801 +
802 +
764 } 803 }
......
...@@ -32,6 +32,7 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -32,6 +32,7 @@ import org.onosproject.net.DefaultAnnotations;
32 import org.onosproject.net.Device; 32 import org.onosproject.net.Device;
33 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
34 import org.onosproject.net.MastershipRole; 34 import org.onosproject.net.MastershipRole;
35 +import org.onosproject.net.PortNumber;
35 import org.onosproject.net.SparseAnnotations; 36 import org.onosproject.net.SparseAnnotations;
36 import org.onosproject.net.device.DefaultDeviceDescription; 37 import org.onosproject.net.device.DefaultDeviceDescription;
37 import org.onosproject.net.device.DeviceDescription; 38 import org.onosproject.net.device.DeviceDescription;
...@@ -148,4 +149,10 @@ public class OvsdbDeviceProvider extends AbstractProvider ...@@ -148,4 +149,10 @@ public class OvsdbDeviceProvider extends AbstractProvider
148 } 149 }
149 return new OvsdbNodeId(IpAddress.valueOf(strings[1]), 0); 150 return new OvsdbNodeId(IpAddress.valueOf(strings[1]), 0);
150 } 151 }
152 +
153 + @Override
154 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
155 + boolean enable) {
156 + // TODO if required
157 + }
151 } 158 }
......
...@@ -34,6 +34,7 @@ import org.onosproject.net.OchPort; ...@@ -34,6 +34,7 @@ import org.onosproject.net.OchPort;
34 import org.onosproject.net.OduCltPort; 34 import org.onosproject.net.OduCltPort;
35 import org.onosproject.net.OmsPort; 35 import org.onosproject.net.OmsPort;
36 import org.onosproject.net.Port; 36 import org.onosproject.net.Port;
37 +import org.onosproject.net.PortNumber;
37 import org.onosproject.net.device.DefaultDeviceDescription; 38 import org.onosproject.net.device.DefaultDeviceDescription;
38 import org.onosproject.net.device.DefaultPortDescription; 39 import org.onosproject.net.device.DefaultPortDescription;
39 import org.onosproject.net.device.DeviceDescription; 40 import org.onosproject.net.device.DeviceDescription;
...@@ -318,4 +319,10 @@ public class PcepTopologyProvider extends AbstractProvider ...@@ -318,4 +319,10 @@ public class PcepTopologyProvider extends AbstractProvider
318 // TODO Auto-generated method stub 319 // TODO Auto-generated method stub
319 return true; 320 return true;
320 } 321 }
322 +
323 + @Override
324 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
325 + boolean enable) {
326 + // TODO Auto-generated method stub
327 + }
321 } 328 }
......
...@@ -31,6 +31,7 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -31,6 +31,7 @@ import org.onosproject.net.DefaultAnnotations;
31 import org.onosproject.net.Device; 31 import org.onosproject.net.Device;
32 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
33 import org.onosproject.net.MastershipRole; 33 import org.onosproject.net.MastershipRole;
34 +import org.onosproject.net.PortNumber;
34 import org.onosproject.net.SparseAnnotations; 35 import org.onosproject.net.SparseAnnotations;
35 import org.onosproject.net.behaviour.PortDiscovery; 36 import org.onosproject.net.behaviour.PortDiscovery;
36 import org.onosproject.net.config.ConfigFactory; 37 import org.onosproject.net.config.ConfigFactory;
...@@ -256,4 +257,10 @@ public class RestDeviceProvider extends AbstractProvider ...@@ -256,4 +257,10 @@ public class RestDeviceProvider extends AbstractProvider
256 event.type() == CONFIG_UPDATED); 257 event.type() == CONFIG_UPDATED);
257 } 258 }
258 } 259 }
260 +
261 + @Override
262 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
263 + boolean enable) {
264 + // TODO if required
265 + }
259 } 266 }
......
...@@ -37,6 +37,7 @@ import org.onosproject.net.DefaultAnnotations; ...@@ -37,6 +37,7 @@ import org.onosproject.net.DefaultAnnotations;
37 import org.onosproject.net.Device; 37 import org.onosproject.net.Device;
38 import org.onosproject.net.DeviceId; 38 import org.onosproject.net.DeviceId;
39 import org.onosproject.net.MastershipRole; 39 import org.onosproject.net.MastershipRole;
40 +import org.onosproject.net.PortNumber;
40 import org.onosproject.net.SparseAnnotations; 41 import org.onosproject.net.SparseAnnotations;
41 import org.onosproject.net.behaviour.PortDiscovery; 42 import org.onosproject.net.behaviour.PortDiscovery;
42 import org.onosproject.net.device.DefaultDeviceDescription; 43 import org.onosproject.net.device.DefaultDeviceDescription;
...@@ -427,4 +428,10 @@ public class SnmpDeviceProvider extends AbstractProvider ...@@ -427,4 +428,10 @@ public class SnmpDeviceProvider extends AbstractProvider
427 protected ISnmpSessionFactory getSessionFactory(ISnmpConfigurationFactory configurationFactory) { 428 protected ISnmpSessionFactory getSessionFactory(ISnmpConfigurationFactory configurationFactory) {
428 return new SnmpSessionFactory(configurationFactory); 429 return new SnmpSessionFactory(configurationFactory);
429 } 430 }
431 +
432 + @Override
433 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
434 + boolean enable) {
435 + // TODO if required
436 + }
430 } 437 }
......
...@@ -568,6 +568,11 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { ...@@ -568,6 +568,11 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
568 } 568 }
569 569
570 @Override 570 @Override
571 + public void changePortState(DeviceId deviceId, PortNumber portNumber,
572 + boolean enable) {
573 + }
574 +
575 + @Override
571 public ProviderId id() { 576 public ProviderId id() {
572 return PID; 577 return PID;
573 } 578 }
...@@ -610,4 +615,6 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { ...@@ -610,4 +615,6 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
610 } 615 }
611 } 616 }
612 617
618 +
619 +
613 } 620 }
......