Committed by
Gerrit Code Review
[GEANT] Rate limit on port via NetConf and refactoring.
Change-Id: Id5b5a196bed3b28159160b94bc5ae838d00cb765
Showing
5 changed files
with
187 additions
and
53 deletions
... | @@ -35,17 +35,20 @@ import java.util.List; | ... | @@ -35,17 +35,20 @@ import java.util.List; |
35 | description = "Configures a device interface") | 35 | description = "Configures a device interface") |
36 | public class DeviceInterfaceAddCommand extends AbstractShellCommand { | 36 | public class DeviceInterfaceAddCommand extends AbstractShellCommand { |
37 | 37 | ||
38 | + private static final String ONE_ACTION_ALLOWED = | ||
39 | + "One configuration action allowed at a time"; | ||
38 | private static final String CONFIG_VLAN_SUCCESS = | 40 | private static final String CONFIG_VLAN_SUCCESS = |
39 | "VLAN %s added on device %s interface %s."; | 41 | "VLAN %s added on device %s interface %s."; |
40 | private static final String CONFIG_VLAN_FAILURE = | 42 | private static final String CONFIG_VLAN_FAILURE = |
41 | "Failed to add VLAN %s on device %s interface %s."; | 43 | "Failed to add VLAN %s on 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 | - | ||
45 | private static final String CONFIG_TRUNK_SUCCESS = | 44 | private static final String CONFIG_TRUNK_SUCCESS = |
46 | "Trunk mode added for VLAN %s on device %s interface %s."; | 45 | "Trunk mode added for VLAN %s on device %s interface %s."; |
47 | private static final String CONFIG_TRUNK_FAILURE = | 46 | private static final String CONFIG_TRUNK_FAILURE = |
48 | "Failed to add trunk mode for VLAN %s on device %s interface %s."; | 47 | "Failed to add trunk mode for VLAN %s on device %s interface %s."; |
48 | + private static final String CONFIG_RATE_SUCCESS = | ||
49 | + "Rate limit %d%% added on device %s interface %s."; | ||
50 | + private static final String CONFIG_RATE_FAILURE = | ||
51 | + "Failed to add rate limit %d%% on device %s interface %s."; | ||
49 | 52 | ||
50 | @Argument(index = 0, name = "uri", description = "Device ID", | 53 | @Argument(index = 0, name = "uri", description = "Device ID", |
51 | required = true, multiValued = false) | 54 | required = true, multiValued = false) |
... | @@ -56,15 +59,20 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand { | ... | @@ -56,15 +59,20 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand { |
56 | required = true, multiValued = false) | 59 | required = true, multiValued = false) |
57 | private String portName = null; | 60 | private String portName = null; |
58 | 61 | ||
59 | - @Argument(index = 2, name = "vlan", | 62 | + @Option(name = "-r", aliases = "--rate-limit", |
60 | - description = "VLAN ID", | 63 | + description = "Percentage for egress bandwidth limit", |
61 | - required = true, multiValued = true) | 64 | + required = false, multiValued = false) |
62 | - private String[] vlanStrings = null; | 65 | + private String limitString = null; |
63 | 66 | ||
64 | @Option(name = "-t", aliases = "--trunk", | 67 | @Option(name = "-t", aliases = "--trunk", |
65 | - description = "Configure interface as trunk for VLAN(s)", | 68 | + description = "VLAN(s) for trunk port (multiple values are allowed)", |
69 | + required = false, multiValued = true) | ||
70 | + private String[] trunkVlanStrings = null; | ||
71 | + | ||
72 | + @Option(name = "-a", aliases = "--access", | ||
73 | + description = "VLAN for access port", | ||
66 | required = false, multiValued = false) | 74 | required = false, multiValued = false) |
67 | - private boolean trunkMode = false; | 75 | + private String accessVlanString = null; |
68 | 76 | ||
69 | @Override | 77 | @Override |
70 | protected void execute() { | 78 | protected void execute() { |
... | @@ -73,31 +81,51 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand { | ... | @@ -73,31 +81,51 @@ public class DeviceInterfaceAddCommand extends AbstractShellCommand { |
73 | DriverHandler h = service.createHandler(deviceId); | 81 | DriverHandler h = service.createHandler(deviceId); |
74 | InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); | 82 | InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); |
75 | 83 | ||
76 | - List<VlanId> vlanIds = new ArrayList<>(); | 84 | + if (accessVlanString != null && trunkVlanStrings == null && |
77 | - for (String vlanString : vlanStrings) { | 85 | + limitString == null) { |
78 | - vlanIds.add(VlanId.vlanId(Short.parseShort(vlanString))); | 86 | + // Access mode to be enabled for VLAN. |
87 | + addAccessModeToIntf(interfaceConfig); | ||
88 | + } else if (trunkVlanStrings != null && accessVlanString == null && | ||
89 | + limitString == null) { | ||
90 | + // Trunk mode to be enabled for VLANs. | ||
91 | + addTrunkModeToIntf(interfaceConfig); | ||
92 | + } else if (limitString != null && accessVlanString == null && | ||
93 | + trunkVlanStrings == null) { | ||
94 | + // Rate limit to be set on interface. | ||
95 | + addRateLimitToIntf(interfaceConfig); | ||
96 | + } else { | ||
97 | + // Option has not been correctly set. | ||
98 | + print(ONE_ACTION_ALLOWED); | ||
79 | } | 99 | } |
100 | + } | ||
80 | 101 | ||
81 | - if (trunkMode) { | 102 | + private void addRateLimitToIntf(InterfaceConfig config) { |
82 | - // Trunk mode to be enabled for VLAN. | 103 | + short rate = Short.parseShort(limitString); |
83 | - if (interfaceConfig.addTrunkInterface(deviceId, portName, vlanIds)) { | 104 | + if (config.addRateLimit(portName, rate)) { |
84 | - print(CONFIG_TRUNK_SUCCESS, vlanIds, deviceId, portName); | 105 | + print(CONFIG_RATE_SUCCESS, rate, uri, portName); |
85 | - } else { | 106 | + } else { |
86 | - print(CONFIG_TRUNK_FAILURE, vlanIds, deviceId, portName); | 107 | + print(CONFIG_RATE_FAILURE, rate, uri, portName); |
87 | - } | ||
88 | - return; | ||
89 | } | 108 | } |
109 | + } | ||
90 | 110 | ||
91 | - // Access mode to be enabled for VLAN. | 111 | + private void addTrunkModeToIntf(InterfaceConfig config) { |
92 | - if (vlanIds.size() != 1) { | 112 | + List<VlanId> vlanIds = new ArrayList<>(); |
93 | - print(ONE_VLAN_ALLOWED, deviceId, portName); | 113 | + for (String vlanString : trunkVlanStrings) { |
94 | - return; | 114 | + vlanIds.add(VlanId.vlanId(Short.parseShort(vlanString))); |
95 | } | 115 | } |
96 | - VlanId accessVlanId = vlanIds.get(0); | 116 | + if (config.addTrunkMode(portName, vlanIds)) { |
97 | - if (interfaceConfig.addAccessInterface(deviceId, portName, accessVlanId)) { | 117 | + print(CONFIG_TRUNK_SUCCESS, vlanIds, uri, portName); |
98 | - print(CONFIG_VLAN_SUCCESS, accessVlanId, deviceId, portName); | 118 | + } else { |
119 | + print(CONFIG_TRUNK_FAILURE, vlanIds, uri, portName); | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + private void addAccessModeToIntf(InterfaceConfig config) { | ||
124 | + VlanId accessVlanId = VlanId.vlanId(Short.parseShort(accessVlanString)); | ||
125 | + if (config.addAccessMode(portName, accessVlanId)) { | ||
126 | + print(CONFIG_VLAN_SUCCESS, accessVlanId, uri, portName); | ||
99 | } else { | 127 | } else { |
100 | - print(CONFIG_VLAN_FAILURE, accessVlanId, deviceId, portName); | 128 | + print(CONFIG_VLAN_FAILURE, accessVlanId, uri, portName); |
101 | } | 129 | } |
102 | } | 130 | } |
103 | 131 | ... | ... |
... | @@ -25,36 +25,51 @@ import org.onosproject.net.driver.DriverHandler; | ... | @@ -25,36 +25,51 @@ import org.onosproject.net.driver.DriverHandler; |
25 | import org.onosproject.net.driver.DriverService; | 25 | import org.onosproject.net.driver.DriverService; |
26 | 26 | ||
27 | /** | 27 | /** |
28 | - * Removes configured interface from a device. | 28 | + * Removes an interface configurion from a device. |
29 | */ | 29 | */ |
30 | @Command(scope = "onos", name = "device-remove-interface", | 30 | @Command(scope = "onos", name = "device-remove-interface", |
31 | description = "Removes an interface configuration from a device") | 31 | description = "Removes an interface configuration from a device") |
32 | public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { | 32 | public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { |
33 | 33 | ||
34 | + private static final String ONE_ACTION_ALLOWED = | ||
35 | + "One configuration removal allowed at a time"; | ||
34 | private static final String REMOVE_ACCESS_SUCCESS = | 36 | private static final String REMOVE_ACCESS_SUCCESS = |
35 | - "Access mode deleted from device %s interface %s."; | 37 | + "Access mode removed from device %s interface %s."; |
36 | private static final String REMOVE_ACCESS_FAILURE = | 38 | private static final String REMOVE_ACCESS_FAILURE = |
37 | - "Failed to delete access mode from device %s interface %s."; | 39 | + "Failed to remove access mode from device %s interface %s."; |
38 | - | ||
39 | private static final String REMOVE_TRUNK_SUCCESS = | 40 | private static final String REMOVE_TRUNK_SUCCESS = |
40 | - "Trunk mode deleted from device %s interface %s."; | 41 | + "Trunk mode removed from device %s interface %s."; |
41 | private static final String REMOVE_TRUNK_FAILURE = | 42 | private static final String REMOVE_TRUNK_FAILURE = |
42 | - "Failed to delete trunk mode from device %s interface %s."; | 43 | + "Failed to remove trunk mode from device %s interface %s."; |
44 | + private static final String REMOVE_RATE_SUCCESS = | ||
45 | + "Rate limit removed from device %s interface %s."; | ||
46 | + private static final String REMOVE_RATE_FAILURE = | ||
47 | + "Failed to remove rate limit from device %s interface %s."; | ||
43 | 48 | ||
44 | @Argument(index = 0, name = "uri", description = "Device ID", | 49 | @Argument(index = 0, name = "uri", description = "Device ID", |
45 | required = true, multiValued = false) | 50 | required = true, multiValued = false) |
46 | private String uri = null; | 51 | private String uri = null; |
47 | 52 | ||
48 | @Argument(index = 1, name = "interface", | 53 | @Argument(index = 1, name = "interface", |
49 | - description = "Interface name", | 54 | + description = "Interface name", |
50 | - required = true, multiValued = false) | 55 | + required = true, multiValued = false) |
51 | private String portName = null; | 56 | private String portName = null; |
52 | 57 | ||
58 | + @Option(name = "-r", aliases = "--rate-limit", | ||
59 | + description = "Percentage for egress bandwidth limit", | ||
60 | + required = false, multiValued = false) | ||
61 | + private boolean rateLimit = false; | ||
62 | + | ||
53 | @Option(name = "-t", aliases = "--trunk", | 63 | @Option(name = "-t", aliases = "--trunk", |
54 | description = "Remove trunk mode for VLAN(s)", | 64 | description = "Remove trunk mode for VLAN(s)", |
55 | required = false, multiValued = false) | 65 | required = false, multiValued = false) |
56 | private boolean trunkMode = false; | 66 | private boolean trunkMode = false; |
57 | 67 | ||
68 | + @Option(name = "-a", aliases = "--access", | ||
69 | + description = "Remove access mode for VLAN", | ||
70 | + required = false, multiValued = false) | ||
71 | + private boolean accessMode = false; | ||
72 | + | ||
58 | @Override | 73 | @Override |
59 | protected void execute() { | 74 | protected void execute() { |
60 | DriverService service = get(DriverService.class); | 75 | DriverService service = get(DriverService.class); |
... | @@ -62,21 +77,42 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { | ... | @@ -62,21 +77,42 @@ public class DeviceInterfaceRemoveCommand extends AbstractShellCommand { |
62 | DriverHandler h = service.createHandler(deviceId); | 77 | DriverHandler h = service.createHandler(deviceId); |
63 | InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); | 78 | InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); |
64 | 79 | ||
65 | - if (trunkMode) { | 80 | + if (trunkMode && !accessMode && !rateLimit) { |
66 | // Trunk mode for VLAN to be removed. | 81 | // Trunk mode for VLAN to be removed. |
67 | - if (interfaceConfig.removeTrunkInterface(deviceId, portName)) { | 82 | + removeTrunkModeFromIntf(interfaceConfig); |
68 | - print(REMOVE_TRUNK_SUCCESS, deviceId, portName); | 83 | + } else if (accessMode && !trunkMode && !rateLimit) { |
69 | - } else { | 84 | + // Access mode for VLAN to be removed. |
70 | - print(REMOVE_TRUNK_FAILURE, deviceId, portName); | 85 | + removeAccessModeFromIntf(interfaceConfig); |
71 | - } | 86 | + } else if (rateLimit && !trunkMode && !accessMode) { |
72 | - return; | 87 | + // Rate limit to be removed. |
88 | + removeRateLimitFromIntf(interfaceConfig); | ||
89 | + } else { | ||
90 | + // Option has not been correctly set. | ||
91 | + print(ONE_ACTION_ALLOWED); | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + private void removeAccessModeFromIntf(InterfaceConfig interfaceConfig) { | ||
96 | + if (interfaceConfig.removeAccessMode(portName)) { | ||
97 | + print(REMOVE_ACCESS_SUCCESS, uri, portName); | ||
98 | + } else { | ||
99 | + print(REMOVE_ACCESS_FAILURE, uri, portName); | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + private void removeTrunkModeFromIntf(InterfaceConfig interfaceConfig) { | ||
104 | + if (interfaceConfig.removeTrunkMode(portName)) { | ||
105 | + print(REMOVE_TRUNK_SUCCESS, uri, portName); | ||
106 | + } else { | ||
107 | + print(REMOVE_TRUNK_FAILURE, uri, portName); | ||
73 | } | 108 | } |
109 | + } | ||
74 | 110 | ||
75 | - // Access mode for VLAN to be removed. | 111 | + private void removeRateLimitFromIntf(InterfaceConfig config) { |
76 | - if (interfaceConfig.removeAccessInterface(deviceId, portName)) { | 112 | + if (config.removeRateLimit(portName)) { |
77 | - print(REMOVE_ACCESS_SUCCESS, deviceId, portName); | 113 | + print(REMOVE_RATE_SUCCESS, uri, portName); |
78 | } else { | 114 | } else { |
79 | - print(REMOVE_ACCESS_FAILURE, deviceId, portName); | 115 | + print(REMOVE_RATE_FAILURE, uri, portName); |
80 | } | 116 | } |
81 | } | 117 | } |
82 | 118 | ... | ... |
... | @@ -78,7 +78,7 @@ public class DeviceInterfacesListCommand extends DevicesListCommand { | ... | @@ -78,7 +78,7 @@ public class DeviceInterfacesListCommand extends DevicesListCommand { |
78 | InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); | 78 | InterfaceConfig interfaceConfig = h.behaviour(InterfaceConfig.class); |
79 | 79 | ||
80 | List<DeviceInterfaceDescription> interfaces = | 80 | List<DeviceInterfaceDescription> interfaces = |
81 | - interfaceConfig.getInterfaces(device.id()); | 81 | + interfaceConfig.getInterfaces(); |
82 | if (interfaces == null) { | 82 | if (interfaces == null) { |
83 | print(ERROR_RESULT); | 83 | print(ERROR_RESULT); |
84 | } else if (interfaces.isEmpty()) { | 84 | } else if (interfaces.isEmpty()) { | ... | ... |
... | @@ -34,8 +34,19 @@ public interface InterfaceConfig extends HandlerBehaviour { | ... | @@ -34,8 +34,19 @@ public interface InterfaceConfig extends HandlerBehaviour { |
34 | * @param intf the name of the interface | 34 | * @param intf the name of the interface |
35 | * @param vlanId the VLAN ID | 35 | * @param vlanId the VLAN ID |
36 | * @return the result of operation | 36 | * @return the result of operation |
37 | + * @deprecated in 1.7.0 Hummingbird release - use of addAccessMode() instead | ||
37 | */ | 38 | */ |
38 | - boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId); | 39 | + @Deprecated |
40 | + public boolean addAccessInterface(DeviceId deviceId, String intf, VlanId vlanId); | ||
41 | + | ||
42 | + /** | ||
43 | + * Adds an access interface to a VLAN. | ||
44 | + * | ||
45 | + * @param intf the name of the interface | ||
46 | + * @param vlanId the VLAN ID | ||
47 | + * @return the result of operation | ||
48 | + */ | ||
49 | + boolean addAccessMode(String intf, VlanId vlanId); | ||
39 | 50 | ||
40 | /** | 51 | /** |
41 | * Removes an access interface to a VLAN. | 52 | * Removes an access interface to a VLAN. |
... | @@ -43,40 +54,99 @@ public interface InterfaceConfig extends HandlerBehaviour { | ... | @@ -43,40 +54,99 @@ public interface InterfaceConfig extends HandlerBehaviour { |
43 | * @param deviceId the device ID | 54 | * @param deviceId the device ID |
44 | * @param intf the name of the interface | 55 | * @param intf the name of the interface |
45 | * @return the result of operation | 56 | * @return the result of operation |
57 | + * @deprecated in 1.7.0 Hummingbird release - use of removeAccessMode() instead | ||
46 | */ | 58 | */ |
59 | + @Deprecated | ||
47 | boolean removeAccessInterface(DeviceId deviceId, String intf); | 60 | boolean removeAccessInterface(DeviceId deviceId, String intf); |
48 | 61 | ||
49 | /** | 62 | /** |
63 | + * Removes an access interface to a VLAN. | ||
64 | + * | ||
65 | + * @param intf the name of the interface | ||
66 | + * @return the result of operation | ||
67 | + */ | ||
68 | + boolean removeAccessMode(String intf); | ||
69 | + | ||
70 | + /** | ||
50 | * Adds a trunk interface for VLANs. | 71 | * Adds a trunk interface for VLANs. |
51 | * | 72 | * |
52 | * @param deviceId the device ID | 73 | * @param deviceId the device ID |
53 | * @param intf the name of the interface | 74 | * @param intf the name of the interface |
54 | * @param vlanIds the VLAN IDs | 75 | * @param vlanIds the VLAN IDs |
55 | * @return the result of operation | 76 | * @return the result of operation |
77 | + * @deprecated in 1.7.0 Hummingbird release - use of addTrunkMode() instead | ||
56 | */ | 78 | */ |
79 | + @Deprecated | ||
57 | boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds); | 80 | boolean addTrunkInterface(DeviceId deviceId, String intf, List<VlanId> vlanIds); |
58 | 81 | ||
59 | /** | 82 | /** |
60 | - * Removes trunk mode configuration from an interface. | 83 | + * Adds a trunk interface for VLANs. |
84 | + * | ||
85 | + * @param intf the name of the interface | ||
86 | + * @param vlanIds the VLAN IDs | ||
87 | + * @return the result of operation | ||
88 | + */ | ||
89 | + boolean addTrunkMode(String intf, List<VlanId> vlanIds); | ||
90 | + | ||
91 | + /** | ||
92 | + * Removes trunk mode configuration from an interface. | ||
61 | * | 93 | * |
62 | * @param deviceId the device ID | 94 | * @param deviceId the device ID |
63 | * @param intf the name of the interface | 95 | * @param intf the name of the interface |
64 | * @return the result of operation | 96 | * @return the result of operation |
97 | + * @deprecated in 1.7.0 Hummingbird release - use of removeTrunkMode() instead | ||
65 | */ | 98 | */ |
99 | + @Deprecated | ||
66 | boolean removeTrunkInterface(DeviceId deviceId, String intf); | 100 | boolean removeTrunkInterface(DeviceId deviceId, String intf); |
67 | 101 | ||
68 | /** | 102 | /** |
103 | + * Removes trunk mode configuration from an interface. | ||
104 | + * | ||
105 | + * @param intf the name of the interface | ||
106 | + * @return the result of operation | ||
107 | + */ | ||
108 | + boolean removeTrunkMode(String intf); | ||
109 | + | ||
110 | + /** | ||
111 | + * Adds a rate limit on an interface. | ||
112 | + * | ||
113 | + * @param intf the name of the interface | ||
114 | + * @param limit the limit as a percentage | ||
115 | + * @return the result of operation | ||
116 | + */ | ||
117 | + boolean addRateLimit(String intf, short limit); | ||
118 | + | ||
119 | + /** | ||
120 | + * Removes rate limit from an interface. | ||
121 | + * | ||
122 | + * @param intf the name of the interface | ||
123 | + * @return the result of operation | ||
124 | + */ | ||
125 | + boolean removeRateLimit(String intf); | ||
126 | + | ||
127 | + /** | ||
69 | * Provides the interfaces configured on a device. | 128 | * Provides the interfaces configured on a device. |
70 | * | 129 | * |
71 | * @param deviceId the device ID | 130 | * @param deviceId the device ID |
72 | * @return the list of the configured interfaces | 131 | * @return the list of the configured interfaces |
132 | + * @deprecated in 1.7.0 Hummingbird release - use of getInterfaces() without | ||
133 | + * deviceId as parameter instead | ||
134 | + */ | ||
135 | + @Deprecated | ||
136 | + public List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId); | ||
137 | + | ||
138 | + /** | ||
139 | + * Provides the interfaces configured on a device. | ||
140 | + * | ||
141 | + * @return the list of the configured interfaces | ||
73 | */ | 142 | */ |
74 | - List<DeviceInterfaceDescription> getInterfaces(DeviceId deviceId); | 143 | + List<DeviceInterfaceDescription> getInterfaces(); |
75 | 144 | ||
76 | /** | 145 | /** |
77 | * TODO Addition of more methods to make the behavior symmetrical. | 146 | * TODO Addition of more methods to make the behavior symmetrical. |
78 | - * Methods getInterfacesForVlan, getVlansForInterface, getTrunkforInterface, | 147 | + * Methods getInterfacesForVlan(VlanId), hasAccessMode(), hasTrunkMode(), |
79 | - * getInterfacesForTrunk should be added to complete the behavior. | 148 | + * getTrunkVlans(Interface), getAccessVlan(Interface) should be added to |
149 | + * complete the behavior. | ||
80 | */ | 150 | */ |
81 | 151 | ||
82 | } | 152 | } | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment