Andreas Papazois
Committed by Gerrit Code Review

[GEANT] VLAN arg not needed when removing interface.

Change-Id: I9015f7df65b924901dab7c32a7dd757f7fa55234
...@@ -94,7 +94,7 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand { ...@@ -94,7 +94,7 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand {
94 return; 94 return;
95 } 95 }
96 VlanId accessVlanId = vlanIds.get(0); 96 VlanId accessVlanId = vlanIds.get(0);
97 - if (interfaceConfig.addInterfaceToVlan(deviceId, portName, accessVlanId)) { 97 + if (interfaceConfig.addAccessInterface(deviceId, portName, accessVlanId)) {
98 print(CONFIG_VLAN_SUCCESS, accessVlanId, deviceId, portName); 98 print(CONFIG_VLAN_SUCCESS, accessVlanId, deviceId, portName);
99 } else { 99 } else {
100 print(CONFIG_VLAN_FAILURE, accessVlanId, deviceId, portName); 100 print(CONFIG_VLAN_FAILURE, accessVlanId, deviceId, portName);
......
...@@ -18,16 +18,12 @@ package org.onosproject.cli.net; ...@@ -18,16 +18,12 @@ package org.onosproject.cli.net;
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 import org.apache.karaf.shell.commands.Option; 20 import org.apache.karaf.shell.commands.Option;
21 -import org.onlab.packet.VlanId;
22 import org.onosproject.cli.AbstractShellCommand; 21 import org.onosproject.cli.AbstractShellCommand;
23 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
24 import org.onosproject.net.behaviour.InterfaceConfig; 23 import org.onosproject.net.behaviour.InterfaceConfig;
25 import org.onosproject.net.driver.DriverHandler; 24 import org.onosproject.net.driver.DriverHandler;
26 import org.onosproject.net.driver.DriverService; 25 import org.onosproject.net.driver.DriverService;
27 26
28 -import java.util.ArrayList;
29 -import java.util.List;
30 -
31 /** 27 /**
32 * Removes configured interface from a device. 28 * Removes configured interface from a device.
33 */ 29 */
...@@ -35,17 +31,15 @@ import java.util.List; ...@@ -35,17 +31,15 @@ import java.util.List;
35 description = "Removes an interface configuration from a device") 31 description = "Removes an interface configuration from a device")
36 public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { 32 public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
37 33
38 - private static final String REMOVE_VLAN_SUCCESS = 34 + private static final String REMOVE_ACCESS_SUCCESS =
39 - "VLAN %s removed from device %s interface %s."; 35 + "Access mode deleted from device %s interface %s.";
40 - private static final String REMOVE_VLAN_FAILURE = 36 + private static final String REMOVE_ACCESS_FAILURE =
41 - "Failed to remove VLAN %s from device %s interface %s."; 37 + "Failed to delete access mode from device %s interface %s.";
42 - private static final String ONE_VLAN_ALLOWED =
43 - "Only one VLAN allowed for access mode on device %s interface %s.";
44 38
45 private static final String REMOVE_TRUNK_SUCCESS = 39 private static final String REMOVE_TRUNK_SUCCESS =
46 - "Trunk mode removed for VLAN %s on device %s interface %s."; 40 + "Trunk mode deleted from device %s interface %s.";
47 private static final String REMOVE_TRUNK_FAILURE = 41 private static final String REMOVE_TRUNK_FAILURE =
48 - "Failed to remove trunk mode for VLAN %s on device %s interface %s."; 42 + "Failed to delete trunk mode from device %s interface %s.";
49 43
50 @Argument(index = 0, name = "uri", description = "Device ID", 44 @Argument(index = 0, name = "uri", description = "Device ID",
51 required = true, multiValued = false) 45 required = true, multiValued = false)
...@@ -56,11 +50,6 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { ...@@ -56,11 +50,6 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
56 required = true, multiValued = false) 50 required = true, multiValued = false)
57 private String portName = null; 51 private String portName = null;
58 52
59 - @Argument(index = 2, name = "vlan",
60 - description = "VLAN ID",
61 - required = true, multiValued = true)
62 - private String[] vlanStrings = null;
63 -
64 @Option(name = "-t", aliases = "--trunk", 53 @Option(name = "-t", aliases = "--trunk",
65 description = "Remove trunk mode for VLAN(s)", 54 description = "Remove trunk mode for VLAN(s)",
66 required = false, multiValued = false) 55 required = false, multiValued = false)
...@@ -73,31 +62,21 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { ...@@ -73,31 +62,21 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand {
73 DriverHandler h = service.createHandler(deviceId); 62 DriverHandler h = service.createHandler(deviceId);
74 InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); 63 InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class);
75 64
76 - List<VlanId> vlanIds = new ArrayList<>();
77 - for (String vlanString : vlanStrings) {
78 - vlanIds.add(VlanId.vlanId(Short.parseShort(vlanString)));
79 - }
80 -
81 if (trunkMode) { 65 if (trunkMode) {
82 // Trunk mode for VLAN to be removed. 66 // Trunk mode for VLAN to be removed.
83 - if (interfaceConfig.removeTrunkInterface(deviceId, portName, vlanIds)) { 67 + if (interfaceConfig.removeTrunkInterface(deviceId, portName)) {
84 - print(REMOVE_TRUNK_SUCCESS, vlanIds, deviceId, portName); 68 + print(REMOVE_TRUNK_SUCCESS, deviceId, portName);
85 } else { 69 } else {
86 - print(REMOVE_TRUNK_FAILURE, vlanIds, deviceId, portName); 70 + print(REMOVE_TRUNK_FAILURE, deviceId, portName);
87 } 71 }
88 return; 72 return;
89 } 73 }
90 74
91 // Access mode for VLAN to be removed. 75 // Access mode for VLAN to be removed.
92 - if (vlanIds.size() != 1) { 76 + if (interfaceConfig.removeAccessInterface(deviceId, portName)) {
93 - print(ONE_VLAN_ALLOWED, deviceId, portName); 77 + print(REMOVE_ACCESS_SUCCESS, deviceId, portName);
94 - return;
95 - }
96 - VlanId accessVlanId = vlanIds.get(0);
97 - if (interfaceConfig.removeInterfaceFromVlan(deviceId, portName, accessVlanId)) {
98 - print(REMOVE_VLAN_SUCCESS, accessVlanId, deviceId, portName);
99 } else { 78 } else {
100 - print(REMOVE_VLAN_FAILURE, accessVlanId, deviceId, portName); 79 + print(REMOVE_ACCESS_FAILURE, deviceId, portName);
101 } 80 }
102 } 81 }
103 82
......
...@@ -27,25 +27,24 @@ import java.util.List; ...@@ -27,25 +27,24 @@ import java.util.List;
27 public interface InterfaceConfig extends HandlerBehaviour { 27 public interface InterfaceConfig extends HandlerBehaviour {
28 28
29 /** 29 /**
30 - * Adds an interface to a VLAN. 30 + * Adds an access interface to a VLAN.
31 * @param deviceId the device ID 31 * @param deviceId the device ID
32 * @param intf the name of the interface 32 * @param intf the name of the interface
33 * @param vlanId the VLAN ID 33 * @param vlanId the VLAN ID
34 * @return the result of operation 34 * @return the result of operation
35 */ 35 */
36 - boolean addInterfaceToVlan(DeviceId deviceId, String intf, VlanId vlanId); 36 + boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId);
37 37
38 /** 38 /**
39 - * Removes an interface from a VLAN. 39 + * Removes an access interface to a VLAN.
40 * @param deviceId the device ID 40 * @param deviceId the device ID
41 * @param intf the name of the interface 41 * @param intf the name of the interface
42 - * @param vlanId the VLAN ID
43 * @return the result of operation 42 * @return the result of operation
44 */ 43 */
45 - boolean removeInterfaceFromVlan(DeviceId deviceId, String intf, VlanId vlanId); 44 + boolean removeAccessInterface(DeviceId deviceId, String intf);
46 45
47 /** 46 /**
48 - * Configures an interface as trunk for VLANs. 47 + * Adds a trunk interface for VLANs.
49 * @param deviceId the device ID 48 * @param deviceId the device ID
50 * @param intf the name of the interface 49 * @param intf the name of the interface
51 * @param vlanIds the VLAN IDs 50 * @param vlanIds the VLAN IDs
...@@ -54,13 +53,12 @@ public interface InterfaceConfig extends HandlerBehaviour { ...@@ -54,13 +53,12 @@ public interface InterfaceConfig extends HandlerBehaviour {
54 boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds); 53 boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds);
55 54
56 /** 55 /**
57 - * Removes trunk mode configuration for VLANs from an interface. 56 + * Removes trunk mode configuration from an interface.
58 * @param deviceId the device ID 57 * @param deviceId the device ID
59 * @param intf the name of the interface 58 * @param intf the name of the interface
60 - * @param vlanIds the VLAN IDs
61 * @return the result of operation 59 * @return the result of operation
62 */ 60 */
63 - boolean removeTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds); 61 + boolean removeTrunkInterface(DeviceId deviceId, String intf);
64 62
65 /** 63 /**
66 * TODO Addition of more methods to make the behavior symmetrical. 64 * TODO Addition of more methods to make the behavior symmetrical.
......
...@@ -44,14 +44,14 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -44,14 +44,14 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
44 private final Logger log = getLogger(getClass()); 44 private final Logger log = getLogger(getClass());
45 45
46 /** 46 /**
47 - * Adds an interface to a VLAN. 47 + * Adds an access interface to a VLAN.
48 * @param deviceId the device ID 48 * @param deviceId the device ID
49 * @param intf the name of the interface 49 * @param intf the name of the interface
50 * @param vlanId the VLAN ID 50 * @param vlanId the VLAN ID
51 * @return the result of operation 51 * @return the result of operation
52 */ 52 */
53 @Override 53 @Override
54 - public boolean addInterfaceToVlan(DeviceId deviceId, String intf, VlanId vlanId) { 54 + public boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId) {
55 NetconfController controller = checkNotNull(handler() 55 NetconfController controller = checkNotNull(handler()
56 .get(NetconfController.class)); 56 .get(NetconfController.class));
57 57
...@@ -59,7 +59,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -59,7 +59,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
59 .data().deviceId()).getSession(); 59 .data().deviceId()).getSession();
60 String reply; 60 String reply;
61 try { 61 try {
62 - reply = session.requestSync(addInterfaceToVlanBuilder(intf, vlanId)); 62 + reply = session.requestSync(addAccessInterfaceBuilder(intf, vlanId));
63 } catch (NetconfException e) { 63 } catch (NetconfException e) {
64 log.error("Failed to configure VLAN ID {} on device {} interface {}.", 64 log.error("Failed to configure VLAN ID {} on device {} interface {}.",
65 vlanId, deviceId, intf, e); 65 vlanId, deviceId, intf, e);
...@@ -71,12 +71,12 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -71,12 +71,12 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
71 } 71 }
72 72
73 /** 73 /**
74 - * Builds a request to add an interface to a VLAN. 74 + * Builds a request to add an access interface to a VLAN.
75 * @param intf the name of the interface 75 * @param intf the name of the interface
76 * @param vlanId the VLAN ID 76 * @param vlanId the VLAN ID
77 * @return the request string. 77 * @return the request string.
78 */ 78 */
79 - private String addInterfaceToVlanBuilder(String intf, VlanId vlanId) { 79 + private String addAccessInterfaceBuilder(String intf, VlanId vlanId) {
80 StringBuilder rpc = 80 StringBuilder rpc =
81 new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" "); 81 new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
82 rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); 82 rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
...@@ -106,15 +106,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -106,15 +106,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
106 } 106 }
107 107
108 /** 108 /**
109 - * Removes an interface from a VLAN. 109 + * Removes an access interface to a VLAN.
110 * @param deviceId the device ID 110 * @param deviceId the device ID
111 * @param intf the name of the interface 111 * @param intf the name of the interface
112 - * @param vlanId the VLAN ID
113 * @return the result of operation 112 * @return the result of operation
114 */ 113 */
115 @Override 114 @Override
116 - public boolean removeInterfaceFromVlan(DeviceId deviceId, String intf, 115 + public boolean removeAccessInterface(DeviceId deviceId, String intf) {
117 - VlanId vlanId) {
118 NetconfController controller = checkNotNull(handler() 116 NetconfController controller = checkNotNull(handler()
119 .get(NetconfController.class)); 117 .get(NetconfController.class));
120 118
...@@ -122,10 +120,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -122,10 +120,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
122 .data().deviceId()).getSession(); 120 .data().deviceId()).getSession();
123 String reply; 121 String reply;
124 try { 122 try {
125 - reply = session.requestSync(removeInterfaceFromVlanBuilder(intf, vlanId)); 123 + reply = session.requestSync(removeAccessInterfaceBuilder(intf));
126 } catch (NetconfException e) { 124 } catch (NetconfException e) {
127 - log.error("Failed to remove VLAN ID {} from device {} interface {}.", 125 + log.error("Failed to remove access mode from device {} interface {}.",
128 - vlanId, deviceId, intf, e); 126 + deviceId, intf, e);
129 return false; 127 return false;
130 } 128 }
131 129
...@@ -134,12 +132,11 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -134,12 +132,11 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
134 } 132 }
135 133
136 /** 134 /**
137 - * Builds a request to remove an interface from a VLAN. 135 + * Builds a request to remove an access interface from a VLAN.
138 * @param intf the name of the interface 136 * @param intf the name of the interface
139 - * @param vlanId the VLAN ID
140 * @return the request string. 137 * @return the request string.
141 */ 138 */
142 - private String removeInterfaceFromVlanBuilder(String intf, VlanId vlanId) { 139 + private String removeAccessInterfaceBuilder(String intf) {
143 StringBuilder rpc = 140 StringBuilder rpc =
144 new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" "); 141 new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
145 rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); 142 rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
...@@ -154,7 +151,6 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -154,7 +151,6 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
154 rpc.append("</Param>"); 151 rpc.append("</Param>");
155 rpc.append("<ConfigIf-Configuration>"); 152 rpc.append("<ConfigIf-Configuration>");
156 rpc.append("<switchport operation=\"delete\"><access><vlan><VLANIDVLANPortAccessMode>"); 153 rpc.append("<switchport operation=\"delete\"><access><vlan><VLANIDVLANPortAccessMode>");
157 - rpc.append(vlanId);
158 rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>"); 154 rpc.append("</VLANIDVLANPortAccessMode></vlan></access></switchport>");
159 rpc.append("<switchport operation=\"delete\"><mode><access/></mode></switchport>"); 155 rpc.append("<switchport operation=\"delete\"><mode><access/></mode></switchport>");
160 rpc.append("</ConfigIf-Configuration>"); 156 rpc.append("</ConfigIf-Configuration>");
...@@ -169,7 +165,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -169,7 +165,7 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
169 } 165 }
170 166
171 /** 167 /**
172 - * Configures an interface as trunk for VLANs. 168 + * Adds a trunk interface for VLANs.
173 * @param deviceId the device ID 169 * @param deviceId the device ID
174 * @param intf the name of the interface 170 * @param intf the name of the interface
175 * @param vlanIds the VLAN IDs 171 * @param vlanIds the VLAN IDs
...@@ -233,14 +229,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -233,14 +229,13 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
233 } 229 }
234 230
235 /** 231 /**
236 - * Removes trunk mode configuration for VLANs from an interface. 232 + * Removes trunk mode configuration from an interface.
237 * @param deviceId the device ID 233 * @param deviceId the device ID
238 * @param intf the name of the interface 234 * @param intf the name of the interface
239 - * @param vlanIds the VLAN IDs
240 * @return the result of operation 235 * @return the result of operation
241 */ 236 */
242 @Override 237 @Override
243 - public boolean removeTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds) { 238 + public boolean removeTrunkInterface(DeviceId deviceId, String intf) {
244 NetconfController controller = checkNotNull(handler() 239 NetconfController controller = checkNotNull(handler()
245 .get(NetconfController.class)); 240 .get(NetconfController.class));
246 241
...@@ -248,10 +243,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -248,10 +243,10 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
248 .data().deviceId()).getSession(); 243 .data().deviceId()).getSession();
249 String reply; 244 String reply;
250 try { 245 try {
251 - reply = session.requestSync(removeTrunkInterfaceBuilder(intf, vlanIds)); 246 + reply = session.requestSync(removeTrunkInterfaceBuilder(intf));
252 } catch (NetconfException e) { 247 } catch (NetconfException e) {
253 - log.error("Failed to remove trunk mode for VLAN ID {} on device {} interface {}.", 248 + log.error("Failed to remove trunk mode on device {} interface {}.",
254 - vlanIds, deviceId, intf, e); 249 + deviceId, intf, e);
255 return false; 250 return false;
256 } 251 }
257 252
...@@ -260,12 +255,11 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -260,12 +255,11 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
260 } 255 }
261 256
262 /** 257 /**
263 - * Builds a request to remove trunk mode configuration for VLANs from an interface. 258 + * Builds a request to remove trunk mode configuration from an interface.
264 * @param intf the name of the interface 259 * @param intf the name of the interface
265 - * @param vlanIds the VLAN IDs
266 * @return the request string. 260 * @return the request string.
267 */ 261 */
268 - private String removeTrunkInterfaceBuilder(String intf, List<VlanId> vlanIds) { 262 + private String removeTrunkInterfaceBuilder(String intf) {
269 StringBuilder rpc = 263 StringBuilder rpc =
270 new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" "); 264 new StringBuilder("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ");
271 rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"); 265 rpc.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
...@@ -284,7 +278,6 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour ...@@ -284,7 +278,6 @@ public class InterfaceConfigCiscoIosImpl extends AbstractHandlerBehaviour
284 rpc.append("<dot1q/></encapsulation></trunk></switchport>"); 278 rpc.append("<dot1q/></encapsulation></trunk></switchport>");
285 rpc.append("<switchport><trunk operation=\"delete\"><allowed><vlan>"); 279 rpc.append("<switchport><trunk operation=\"delete\"><allowed><vlan>");
286 rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>"); 280 rpc.append("<VLANIDsAllowedVLANsPortTrunkingMode>");
287 - rpc.append(getVlansString(vlanIds));
288 rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>"); 281 rpc.append("</VLANIDsAllowedVLANsPortTrunkingMode></vlan></allowed>");
289 rpc.append("</trunk></switchport></ConfigIf-Configuration>"); 282 rpc.append("</trunk></switchport></ConfigIf-Configuration>");
290 rpc.append("</interface>"); 283 rpc.append("</interface>");
......