Committed by
Gerrit Code Review
[ONOS-3585] Add the cli of setting external port name.
Change-Id: I71833063c8e3f27fff7d69499cd3d24fd5537274
Showing
5 changed files
with
126 additions
and
34 deletions
| ... | @@ -49,5 +49,9 @@ | ... | @@ -49,5 +49,9 @@ |
| 49 | <artifactId>onos-app-vtn-rsc</artifactId> | 49 | <artifactId>onos-app-vtn-rsc</artifactId> |
| 50 | <version>${project.version}</version> | 50 | <version>${project.version}</version> |
| 51 | </dependency> | 51 | </dependency> |
| 52 | + <dependency> | ||
| 53 | + <groupId>org.apache.karaf.shell</groupId> | ||
| 54 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
| 55 | + </dependency> | ||
| 52 | </dependencies> | 56 | </dependencies> |
| 53 | </project> | 57 | </project> | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vtn.cli; | ||
| 17 | + | ||
| 18 | +import org.apache.karaf.shell.commands.Command; | ||
| 19 | +import org.apache.karaf.shell.commands.Option; | ||
| 20 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | +import org.onosproject.vtn.manager.impl.VTNManager; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Supports for updating the external gateway virtualPort. | ||
| 25 | + */ | ||
| 26 | +@Command(scope = "onos", name = "externalportname-set", | ||
| 27 | + description = "Supports for setting the external port name.") | ||
| 28 | +public class VtnCommand extends AbstractShellCommand { | ||
| 29 | + | ||
| 30 | + @Option(name = "-n", aliases = "--name", description = "external port name.", required = true, | ||
| 31 | + multiValued = false) | ||
| 32 | + String exPortName = ""; | ||
| 33 | + | ||
| 34 | + @Override | ||
| 35 | + protected void execute() { | ||
| 36 | + VTNManager.setExPortName(exPortName); | ||
| 37 | + } | ||
| 38 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * VTN application that applies configuration and flows to the device. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.vtn.cli; |
| ... | @@ -26,6 +26,7 @@ import java.util.Iterator; | ... | @@ -26,6 +26,7 @@ import java.util.Iterator; |
| 26 | import java.util.List; | 26 | import java.util.List; |
| 27 | import java.util.Map; | 27 | import java.util.Map; |
| 28 | import java.util.Set; | 28 | import java.util.Set; |
| 29 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 29 | import java.util.stream.Collectors; | 30 | import java.util.stream.Collectors; |
| 30 | 31 | ||
| 31 | import org.apache.felix.scr.annotations.Activate; | 32 | import org.apache.felix.scr.annotations.Activate; |
| ... | @@ -84,8 +85,12 @@ import org.onosproject.vtn.table.DnatService; | ... | @@ -84,8 +85,12 @@ import org.onosproject.vtn.table.DnatService; |
| 84 | import org.onosproject.vtn.table.L2ForwardService; | 85 | import org.onosproject.vtn.table.L2ForwardService; |
| 85 | import org.onosproject.vtn.table.L3ForwardService; | 86 | import org.onosproject.vtn.table.L3ForwardService; |
| 86 | import org.onosproject.vtn.table.SnatService; | 87 | import org.onosproject.vtn.table.SnatService; |
| 88 | +import org.onosproject.vtn.table.impl.ArpServiceImpl; | ||
| 87 | import org.onosproject.vtn.table.impl.ClassifierServiceImpl; | 89 | import org.onosproject.vtn.table.impl.ClassifierServiceImpl; |
| 90 | +import org.onosproject.vtn.table.impl.DnatServiceImpl; | ||
| 88 | import org.onosproject.vtn.table.impl.L2ForwardServiceImpl; | 91 | import org.onosproject.vtn.table.impl.L2ForwardServiceImpl; |
| 92 | +import org.onosproject.vtn.table.impl.L3ForwardServiceImpl; | ||
| 93 | +import org.onosproject.vtn.table.impl.SnatServiceImpl; | ||
| 89 | import org.onosproject.vtn.util.DataPathIdGenerator; | 94 | import org.onosproject.vtn.util.DataPathIdGenerator; |
| 90 | import org.onosproject.vtn.util.VtnConfig; | 95 | import org.onosproject.vtn.util.VtnConfig; |
| 91 | import org.onosproject.vtn.util.VtnData; | 96 | import org.onosproject.vtn.util.VtnData; |
| ... | @@ -94,9 +99,6 @@ import org.onosproject.vtnrsc.BindingHostId; | ... | @@ -94,9 +99,6 @@ import org.onosproject.vtnrsc.BindingHostId; |
| 94 | import org.onosproject.vtnrsc.DefaultVirtualPort; | 99 | import org.onosproject.vtnrsc.DefaultVirtualPort; |
| 95 | import org.onosproject.vtnrsc.FixedIp; | 100 | import org.onosproject.vtnrsc.FixedIp; |
| 96 | import org.onosproject.vtnrsc.FloatingIp; | 101 | import org.onosproject.vtnrsc.FloatingIp; |
| 97 | -import org.onosproject.vtnrsc.Router; | ||
| 98 | -import org.onosproject.vtnrsc.RouterGateway; | ||
| 99 | -import org.onosproject.vtnrsc.RouterId; | ||
| 100 | import org.onosproject.vtnrsc.RouterInterface; | 102 | import org.onosproject.vtnrsc.RouterInterface; |
| 101 | import org.onosproject.vtnrsc.SecurityGroup; | 103 | import org.onosproject.vtnrsc.SecurityGroup; |
| 102 | import org.onosproject.vtnrsc.SegmentationId; | 104 | import org.onosproject.vtnrsc.SegmentationId; |
| ... | @@ -110,7 +112,6 @@ import org.onosproject.vtnrsc.event.VtnRscEvent; | ... | @@ -110,7 +112,6 @@ import org.onosproject.vtnrsc.event.VtnRscEvent; |
| 110 | import org.onosproject.vtnrsc.event.VtnRscEventFeedback; | 112 | import org.onosproject.vtnrsc.event.VtnRscEventFeedback; |
| 111 | import org.onosproject.vtnrsc.event.VtnRscListener; | 113 | import org.onosproject.vtnrsc.event.VtnRscListener; |
| 112 | import org.onosproject.vtnrsc.floatingip.FloatingIpService; | 114 | import org.onosproject.vtnrsc.floatingip.FloatingIpService; |
| 113 | -import org.onosproject.vtnrsc.router.RouterService; | ||
| 114 | import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService; | 115 | import org.onosproject.vtnrsc.routerinterface.RouterInterfaceService; |
| 115 | import org.onosproject.vtnrsc.service.VtnRscService; | 116 | import org.onosproject.vtnrsc.service.VtnRscService; |
| 116 | import org.onosproject.vtnrsc.subnet.SubnetService; | 117 | import org.onosproject.vtnrsc.subnet.SubnetService; |
| ... | @@ -173,9 +174,6 @@ public class VTNManager implements VTNService { | ... | @@ -173,9 +174,6 @@ public class VTNManager implements VTNService { |
| 173 | protected FloatingIpService floatingIpService; | 174 | protected FloatingIpService floatingIpService; |
| 174 | 175 | ||
| 175 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 176 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 176 | - protected RouterService routerService; | ||
| 177 | - | ||
| 178 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 179 | protected RouterInterfaceService routerInterfaceService; | 177 | protected RouterInterfaceService routerInterfaceService; |
| 180 | 178 | ||
| 181 | private ApplicationId appId; | 179 | private ApplicationId appId; |
| ... | @@ -190,10 +188,10 @@ public class VTNManager implements VTNService { | ... | @@ -190,10 +188,10 @@ public class VTNManager implements VTNService { |
| 190 | private final DeviceListener deviceListener = new InnerDeviceListener(); | 188 | private final DeviceListener deviceListener = new InnerDeviceListener(); |
| 191 | private final VtnRscListener l3EventListener = new VtnL3EventListener(); | 189 | private final VtnRscListener l3EventListener = new VtnL3EventListener(); |
| 192 | 190 | ||
| 191 | + private static String exPortName = "eth0"; | ||
| 193 | private static final String IFACEID = "ifaceid"; | 192 | private static final String IFACEID = "ifaceid"; |
| 194 | private static final String CONTROLLER_IP_KEY = "ipaddress"; | 193 | private static final String CONTROLLER_IP_KEY = "ipaddress"; |
| 195 | public static final String DRIVER_NAME = "onosfw"; | 194 | public static final String DRIVER_NAME = "onosfw"; |
| 196 | - private static final String EX_PORT_NAME = "eth0"; | ||
| 197 | private static final String VIRTUALPORT = "vtn-virtual-port"; | 195 | private static final String VIRTUALPORT = "vtn-virtual-port"; |
| 198 | private static final String SWITCHES_OF_CONTROLLER = "switchesOfController"; | 196 | private static final String SWITCHES_OF_CONTROLLER = "switchesOfController"; |
| 199 | private static final String SWITCH_OF_LOCAL_HOST_PORTS = "switchOfLocalHostPorts"; | 197 | private static final String SWITCH_OF_LOCAL_HOST_PORTS = "switchOfLocalHostPorts"; |
| ... | @@ -215,9 +213,14 @@ public class VTNManager implements VTNService { | ... | @@ -215,9 +213,14 @@ public class VTNManager implements VTNService { |
| 215 | appId = coreService.registerApplication(APP_ID); | 213 | appId = coreService.registerApplication(APP_ID); |
| 216 | classifierService = new ClassifierServiceImpl(appId); | 214 | classifierService = new ClassifierServiceImpl(appId); |
| 217 | l2ForwardService = new L2ForwardServiceImpl(appId); | 215 | l2ForwardService = new L2ForwardServiceImpl(appId); |
| 216 | + arpService = new ArpServiceImpl(appId); | ||
| 217 | + l3ForwardService = new L3ForwardServiceImpl(appId); | ||
| 218 | + snatService = new SnatServiceImpl(appId); | ||
| 219 | + dnatService = new DnatServiceImpl(appId); | ||
| 218 | 220 | ||
| 219 | deviceService.addListener(deviceListener); | 221 | deviceService.addListener(deviceListener); |
| 220 | hostService.addListener(hostListener); | 222 | hostService.addListener(hostListener); |
| 223 | + vtnRscService.addListener(l3EventListener); | ||
| 221 | 224 | ||
| 222 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | 225 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 223 | .register(KryoNamespaces.API) | 226 | .register(KryoNamespaces.API) |
| ... | @@ -307,7 +310,7 @@ public class VTNManager implements VTNService { | ... | @@ -307,7 +310,7 @@ public class VTNManager implements VTNService { |
| 307 | config.driver(DRIVER_NAME); | 310 | config.driver(DRIVER_NAME); |
| 308 | configService.applyConfig(deviceId, BasicDeviceConfig.class, config.node()); | 311 | configService.applyConfig(deviceId, BasicDeviceConfig.class, config.node()); |
| 309 | // Add Bridge | 312 | // Add Bridge |
| 310 | - VtnConfig.applyBridgeConfig(handler, dpid, EX_PORT_NAME); | 313 | + VtnConfig.applyBridgeConfig(handler, dpid, exPortName); |
| 311 | log.info("A new ovs is created in node {}", localIp.toString()); | 314 | log.info("A new ovs is created in node {}", localIp.toString()); |
| 312 | switchesOfController.put(localIp, true); | 315 | switchesOfController.put(localIp, true); |
| 313 | } | 316 | } |
| ... | @@ -471,6 +474,28 @@ public class VTNManager implements VTNService { | ... | @@ -471,6 +474,28 @@ public class VTNManager implements VTNService { |
| 471 | if (virtualPort == null) { | 474 | if (virtualPort == null) { |
| 472 | virtualPort = VtnData.getPort(vPortStore, virtualPortId); | 475 | virtualPort = VtnData.getPort(vPortStore, virtualPortId); |
| 473 | } | 476 | } |
| 477 | + Iterator<FixedIp> fixip = virtualPort.fixedIps().iterator(); | ||
| 478 | + SubnetId subnetId = null; | ||
| 479 | + if (fixip.hasNext()) { | ||
| 480 | + subnetId = fixip.next().subnetId(); | ||
| 481 | + } | ||
| 482 | + if (subnetId != null) { | ||
| 483 | + Map<HostId, Host> hosts = new ConcurrentHashMap(); | ||
| 484 | + if (hostsOfSubnet.get(subnetId) != null) { | ||
| 485 | + hosts = hostsOfSubnet.get(subnetId); | ||
| 486 | + } | ||
| 487 | + if (type == Objective.Operation.ADD) { | ||
| 488 | + hosts.put(host.id(), host); | ||
| 489 | + hostsOfSubnet.put(subnetId, hosts); | ||
| 490 | + } else if (type == Objective.Operation.REMOVE) { | ||
| 491 | + hosts.remove(host.id()); | ||
| 492 | + if (hosts.size() != 0) { | ||
| 493 | + hostsOfSubnet.put(subnetId, hosts); | ||
| 494 | + } else { | ||
| 495 | + hostsOfSubnet.remove(subnetId); | ||
| 496 | + } | ||
| 497 | + } | ||
| 498 | + } | ||
| 474 | 499 | ||
| 475 | Iterable<Device> devices = deviceService.getAvailableDevices(); | 500 | Iterable<Device> devices = deviceService.getAvailableDevices(); |
| 476 | PortNumber inPort = host.location().port(); | 501 | PortNumber inPort = host.location().port(); |
| ... | @@ -887,15 +912,8 @@ public class VTNManager implements VTNService { | ... | @@ -887,15 +912,8 @@ public class VTNManager implements VTNService { |
| 887 | List gwIpMac = getGwIpAndMac(vmPort); | 912 | List gwIpMac = getGwIpAndMac(vmPort); |
| 888 | IpAddress dstVmGwIp = (IpAddress) gwIpMac.get(0); | 913 | IpAddress dstVmGwIp = (IpAddress) gwIpMac.get(0); |
| 889 | MacAddress dstVmGwMac = (MacAddress) gwIpMac.get(1); | 914 | MacAddress dstVmGwMac = (MacAddress) gwIpMac.get(1); |
| 890 | - FixedIp fixedGwIp = getGwFixedIp(floatingIp); | 915 | + List fGwIpMac = getGwIpAndMac(fipPort); |
| 891 | - MacAddress fGwMac = null; | 916 | + MacAddress fGwMac = (MacAddress) fGwIpMac.get(1); |
| 892 | - if (fixedGwIp != null) { | ||
| 893 | - VirtualPort gwPort = virtualPortService.getPort(fixedGwIp); | ||
| 894 | - if (gwPort == null) { | ||
| 895 | - gwPort = VtnData.getPort(vPortStore, fixedGwIp); | ||
| 896 | - } | ||
| 897 | - fGwMac = gwPort.macAddress(); | ||
| 898 | - } | ||
| 899 | TenantNetwork vmNetwork = tenantNetworkService | 917 | TenantNetwork vmNetwork = tenantNetworkService |
| 900 | .getNetwork(vmPort.networkId()); | 918 | .getNetwork(vmPort.networkId()); |
| 901 | TenantNetwork fipNetwork = tenantNetworkService | 919 | TenantNetwork fipNetwork = tenantNetworkService |
| ... | @@ -947,7 +965,7 @@ public class VTNManager implements VTNService { | ... | @@ -947,7 +965,7 @@ public class VTNManager implements VTNService { |
| 947 | Port exPort = null; | 965 | Port exPort = null; |
| 948 | for (Port port : ports) { | 966 | for (Port port : ports) { |
| 949 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); | 967 | String portName = port.annotations().value(AnnotationKeys.PORT_NAME); |
| 950 | - if (portName != null && portName.equals(EX_PORT_NAME)) { | 968 | + if (portName != null && portName.equals(exPortName)) { |
| 951 | exPort = port; | 969 | exPort = port; |
| 952 | break; | 970 | break; |
| 953 | } | 971 | } |
| ... | @@ -977,21 +995,6 @@ public class VTNManager implements VTNService { | ... | @@ -977,21 +995,6 @@ public class VTNManager implements VTNService { |
| 977 | return list; | 995 | return list; |
| 978 | } | 996 | } |
| 979 | 997 | ||
| 980 | - private FixedIp getGwFixedIp(FloatingIp floatingIp) { | ||
| 981 | - RouterId routerId = floatingIp.routerId(); | ||
| 982 | - Router router = routerService.getRouter(routerId); | ||
| 983 | - RouterGateway routerGateway = router.externalGatewayInfo(); | ||
| 984 | - Iterable<FixedIp> externalFixedIps = routerGateway.externalFixedIps(); | ||
| 985 | - FixedIp fixedGwIp = null; | ||
| 986 | - if (externalFixedIps != null) { | ||
| 987 | - Iterator<FixedIp> exFixedIps = externalFixedIps.iterator(); | ||
| 988 | - if (exFixedIps.hasNext()) { | ||
| 989 | - fixedGwIp = exFixedIps.next(); | ||
| 990 | - } | ||
| 991 | - } | ||
| 992 | - return fixedGwIp; | ||
| 993 | - } | ||
| 994 | - | ||
| 995 | private void applyHostMonitoredL3Rules(Host host, | 998 | private void applyHostMonitoredL3Rules(Host host, |
| 996 | Objective.Operation operation) { | 999 | Objective.Operation operation) { |
| 997 | String ifaceId = host.annotations().value(IFACEID); | 1000 | String ifaceId = host.annotations().value(IFACEID); |
| ... | @@ -1060,4 +1063,8 @@ public class VTNManager implements VTNService { | ... | @@ -1060,4 +1063,8 @@ public class VTNManager implements VTNService { |
| 1060 | l3vni, exPort, operation); | 1063 | l3vni, exPort, operation); |
| 1061 | } | 1064 | } |
| 1062 | } | 1065 | } |
| 1066 | + | ||
| 1067 | + public static void setExPortName(String name) { | ||
| 1068 | + exPortName = name; | ||
| 1069 | + } | ||
| 1063 | } | 1070 | } | ... | ... |
| 1 | +<!-- | ||
| 2 | + ~ Copyright 2015 Open Networking Laboratory | ||
| 3 | + ~ | ||
| 4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + ~ you may not use this file except in compliance with the License. | ||
| 6 | + ~ You may obtain a copy of the License at | ||
| 7 | + ~ | ||
| 8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + ~ | ||
| 10 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 11 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + ~ See the License for the specific language governing permissions and | ||
| 14 | + ~ limitations under the License. | ||
| 15 | + --> | ||
| 16 | +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> | ||
| 17 | + | ||
| 18 | + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> | ||
| 19 | + <command> | ||
| 20 | + <action class="org.onosproject.vtn.cli.VtnCommand"/> | ||
| 21 | + </command> | ||
| 22 | + </command-bundle> | ||
| 23 | +</blueprint> |
-
Please register or login to post a comment