Committed by
Gerrit Code Review
Refactored OpenstackRouting to support multiple gateway nodes
Change-Id: I6870ca9a4fd6f6b1cf2d2be72f52ef87827e1d2c
Showing
23 changed files
with
329 additions
and
242 deletions
| ... | @@ -20,7 +20,7 @@ import java.util.Objects; | ... | @@ -20,7 +20,7 @@ import java.util.Objects; |
| 20 | import static com.google.common.base.Preconditions.checkNotNull; | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | 21 | ||
| 22 | /** | 22 | /** |
| 23 | - * An Openstack Neutron Router Interface Model. | 23 | + * An OpenStack Neutron router interface model. |
| 24 | */ | 24 | */ |
| 25 | public final class OpenstackRouterInterface { | 25 | public final class OpenstackRouterInterface { |
| 26 | private final String id; | 26 | private final String id; |
| ... | @@ -37,9 +37,9 @@ public final class OpenstackRouterInterface { | ... | @@ -37,9 +37,9 @@ public final class OpenstackRouterInterface { |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /** | 39 | /** |
| 40 | - * Returns Router Interface ID. | 40 | + * Returns router interface ID. |
| 41 | * | 41 | * |
| 42 | - * @return router interface ID | 42 | + * @return router interface id |
| 43 | */ | 43 | */ |
| 44 | public String id() { | 44 | public String id() { |
| 45 | return id; | 45 | return id; |
| ... | @@ -48,7 +48,7 @@ public final class OpenstackRouterInterface { | ... | @@ -48,7 +48,7 @@ public final class OpenstackRouterInterface { |
| 48 | /** | 48 | /** |
| 49 | * Returns tenant ID. | 49 | * Returns tenant ID. |
| 50 | * | 50 | * |
| 51 | - * @return tenant ID | 51 | + * @return tenant id |
| 52 | */ | 52 | */ |
| 53 | public String tenantId() { | 53 | public String tenantId() { |
| 54 | return tenantId; | 54 | return tenantId; |
| ... | @@ -57,7 +57,7 @@ public final class OpenstackRouterInterface { | ... | @@ -57,7 +57,7 @@ public final class OpenstackRouterInterface { |
| 57 | /** | 57 | /** |
| 58 | * Returns subnet ID. | 58 | * Returns subnet ID. |
| 59 | * | 59 | * |
| 60 | - * @return subnet ID | 60 | + * @return subnet id |
| 61 | */ | 61 | */ |
| 62 | public String subnetId() { | 62 | public String subnetId() { |
| 63 | return subnetId; | 63 | return subnetId; |
| ... | @@ -66,7 +66,7 @@ public final class OpenstackRouterInterface { | ... | @@ -66,7 +66,7 @@ public final class OpenstackRouterInterface { |
| 66 | /** | 66 | /** |
| 67 | * Returns port ID. | 67 | * Returns port ID. |
| 68 | * | 68 | * |
| 69 | - * @return port ID | 69 | + * @return port id |
| 70 | */ | 70 | */ |
| 71 | public String portId() { | 71 | public String portId() { |
| 72 | return portId; | 72 | return portId; |
| ... | @@ -96,7 +96,16 @@ public final class OpenstackRouterInterface { | ... | @@ -96,7 +96,16 @@ public final class OpenstackRouterInterface { |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | /** | 98 | /** |
| 99 | - * An Openstack Router Interface Builder class. | 99 | + * Returns OpenStack router interface builder. |
| 100 | + * | ||
| 101 | + * @return openstack router interface builder | ||
| 102 | + */ | ||
| 103 | + public static Builder builder() { | ||
| 104 | + return new Builder(); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * An OpenStack Router interface builder class. | ||
| 100 | */ | 109 | */ |
| 101 | public static final class Builder { | 110 | public static final class Builder { |
| 102 | private String id; | 111 | private String id; |
| ... | @@ -105,10 +114,10 @@ public final class OpenstackRouterInterface { | ... | @@ -105,10 +114,10 @@ public final class OpenstackRouterInterface { |
| 105 | private String portId; | 114 | private String portId; |
| 106 | 115 | ||
| 107 | /** | 116 | /** |
| 108 | - * Sets Router Interface ID. | 117 | + * Sets router interface ID. |
| 109 | * | 118 | * |
| 110 | - * @param id router interface ID | 119 | + * @param id router interface id |
| 111 | - * @return Builder object | 120 | + * @return builder object |
| 112 | */ | 121 | */ |
| 113 | public Builder id(String id) { | 122 | public Builder id(String id) { |
| 114 | this.id = id; | 123 | this.id = id; |
| ... | @@ -119,7 +128,7 @@ public final class OpenstackRouterInterface { | ... | @@ -119,7 +128,7 @@ public final class OpenstackRouterInterface { |
| 119 | * Sets tenant ID. | 128 | * Sets tenant ID. |
| 120 | * | 129 | * |
| 121 | * @param tenantId tenant ID | 130 | * @param tenantId tenant ID |
| 122 | - * @return Builder object | 131 | + * @return builder object |
| 123 | */ | 132 | */ |
| 124 | public Builder tenantId(String tenantId) { | 133 | public Builder tenantId(String tenantId) { |
| 125 | this.tenantId = tenantId; | 134 | this.tenantId = tenantId; |
| ... | @@ -130,7 +139,7 @@ public final class OpenstackRouterInterface { | ... | @@ -130,7 +139,7 @@ public final class OpenstackRouterInterface { |
| 130 | * Sets subnet ID. | 139 | * Sets subnet ID. |
| 131 | * | 140 | * |
| 132 | * @param subnetId subnet ID | 141 | * @param subnetId subnet ID |
| 133 | - * @return Builder object | 142 | + * @return builder object |
| 134 | */ | 143 | */ |
| 135 | public Builder subnetId(String subnetId) { | 144 | public Builder subnetId(String subnetId) { |
| 136 | this.subnetId = subnetId; | 145 | this.subnetId = subnetId; |
| ... | @@ -141,7 +150,7 @@ public final class OpenstackRouterInterface { | ... | @@ -141,7 +150,7 @@ public final class OpenstackRouterInterface { |
| 141 | * Sets port ID. | 150 | * Sets port ID. |
| 142 | * | 151 | * |
| 143 | * @param portId port ID | 152 | * @param portId port ID |
| 144 | - * @return Builder object | 153 | + * @return builder object |
| 145 | */ | 154 | */ |
| 146 | public Builder portId(String portId) { | 155 | public Builder portId(String portId) { |
| 147 | this.portId = portId; | 156 | this.portId = portId; |
| ... | @@ -149,14 +158,13 @@ public final class OpenstackRouterInterface { | ... | @@ -149,14 +158,13 @@ public final class OpenstackRouterInterface { |
| 149 | } | 158 | } |
| 150 | 159 | ||
| 151 | /** | 160 | /** |
| 152 | - * Builds an Openstack Router Interface object. | 161 | + * Builds an OpenStack router interface object. |
| 153 | * | 162 | * |
| 154 | - * @return OpenstackRouterInterface object | 163 | + * @return openstack router interface object |
| 155 | */ | 164 | */ |
| 156 | public OpenstackRouterInterface build() { | 165 | public OpenstackRouterInterface build() { |
| 157 | return new OpenstackRouterInterface(checkNotNull(id), checkNotNull(tenantId), | 166 | return new OpenstackRouterInterface(checkNotNull(id), checkNotNull(tenantId), |
| 158 | checkNotNull(subnetId), checkNotNull(portId)); | 167 | checkNotNull(subnetId), checkNotNull(portId)); |
| 159 | } | 168 | } |
| 160 | - | ||
| 161 | } | 169 | } |
| 162 | } | 170 | } | ... | ... |
| ... | @@ -13,20 +13,18 @@ | ... | @@ -13,20 +13,18 @@ |
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -package org.onosproject.openstacknetworking.switching; | 16 | +package org.onosproject.openstacknetworking; |
| 17 | 17 | ||
| 18 | import org.onlab.osgi.DefaultServiceDirectory; | 18 | import org.onlab.osgi.DefaultServiceDirectory; |
| 19 | import org.onlab.osgi.ServiceDirectory; | 19 | import org.onlab.osgi.ServiceDirectory; |
| 20 | import org.onlab.packet.Ip4Address; | 20 | import org.onlab.packet.Ip4Address; |
| 21 | import org.onlab.util.Tools; | 21 | import org.onlab.util.Tools; |
| 22 | -import org.onosproject.core.ApplicationId; | ||
| 23 | import org.onosproject.core.CoreService; | 22 | import org.onosproject.core.CoreService; |
| 24 | import org.onosproject.mastership.MastershipService; | 23 | import org.onosproject.mastership.MastershipService; |
| 25 | import org.onosproject.net.Host; | 24 | import org.onosproject.net.Host; |
| 26 | import org.onosproject.net.host.HostEvent; | 25 | import org.onosproject.net.host.HostEvent; |
| 27 | import org.onosproject.net.host.HostListener; | 26 | import org.onosproject.net.host.HostListener; |
| 28 | import org.onosproject.net.host.HostService; | 27 | import org.onosproject.net.host.HostService; |
| 29 | -import org.onosproject.openstacknetworking.Constants; | ||
| 30 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
| 31 | 29 | ||
| 32 | import java.util.Objects; | 30 | import java.util.Objects; |
| ... | @@ -53,7 +51,6 @@ public abstract class AbstractVmHandler { | ... | @@ -53,7 +51,6 @@ public abstract class AbstractVmHandler { |
| 53 | protected MastershipService mastershipService; | 51 | protected MastershipService mastershipService; |
| 54 | protected HostService hostService; | 52 | protected HostService hostService; |
| 55 | 53 | ||
| 56 | - protected ApplicationId appId; | ||
| 57 | protected HostListener hostListener = new InternalHostListener(); | 54 | protected HostListener hostListener = new InternalHostListener(); |
| 58 | 55 | ||
| 59 | protected void activate() { | 56 | protected void activate() { |
| ... | @@ -61,8 +58,6 @@ public abstract class AbstractVmHandler { | ... | @@ -61,8 +58,6 @@ public abstract class AbstractVmHandler { |
| 61 | coreService = services.get(CoreService.class); | 58 | coreService = services.get(CoreService.class); |
| 62 | mastershipService = services.get(MastershipService.class); | 59 | mastershipService = services.get(MastershipService.class); |
| 63 | hostService = services.get(HostService.class); | 60 | hostService = services.get(HostService.class); |
| 64 | - | ||
| 65 | - appId = coreService.registerApplication(Constants.APP_ID); | ||
| 66 | hostService.addListener(hostListener); | 61 | hostService.addListener(hostListener); |
| 67 | 62 | ||
| 68 | log.info("Started"); | 63 | log.info("Started"); |
| ... | @@ -75,9 +70,19 @@ public abstract class AbstractVmHandler { | ... | @@ -75,9 +70,19 @@ public abstract class AbstractVmHandler { |
| 75 | log.info("Stopped"); | 70 | log.info("Stopped"); |
| 76 | } | 71 | } |
| 77 | 72 | ||
| 78 | - abstract void hostDetected(Host host); | 73 | + /** |
| 74 | + * Performs any action when a host is detected. | ||
| 75 | + * | ||
| 76 | + * @param host detected host | ||
| 77 | + */ | ||
| 78 | + protected abstract void hostDetected(Host host); | ||
| 79 | 79 | ||
| 80 | - abstract void hostRemoved(Host host); | 80 | + /** |
| 81 | + * Performs any action when a host is removed. | ||
| 82 | + * | ||
| 83 | + * @param host removed host | ||
| 84 | + */ | ||
| 85 | + protected abstract void hostRemoved(Host host); | ||
| 81 | 86 | ||
| 82 | protected boolean isValidHost(Host host) { | 87 | protected boolean isValidHost(Host host) { |
| 83 | return !host.ipAddresses().isEmpty() && | 88 | return !host.ipAddresses().isEmpty() && | ... | ... |
| ... | @@ -28,23 +28,27 @@ public final class Constants { | ... | @@ -28,23 +28,27 @@ public final class Constants { |
| 28 | private Constants() { | 28 | private Constants() { |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | - public static final String APP_ID = "org.onosproject.openstackswitching"; | 31 | + public static final String SWITCHING_APP_ID = "org.onosproject.openstackswitching"; |
| 32 | + public static final String ROUTING_APP_ID = "org.onosproject.openstackrouting"; | ||
| 32 | 33 | ||
| 33 | - public static final String PORTNAME_PREFIX_VM = "tap"; | 34 | + public static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; |
| 34 | - public static final String PORTNAME_PREFIX_ROUTER = "qr-"; | 35 | + public static final String DEVICE_OWNER_ROUTER_GATEWAY = "network:router_gateway"; |
| 35 | - public static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; | 36 | + public static final String DEVICE_OWNER_FLOATING_IP = "network:floatingip"; |
| 36 | 37 | ||
| 37 | - public static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | 38 | + public static final String PORT_NAME_PREFIX_VM = "tap"; |
| 39 | + public static final String PORT_NAME_PREFIX_TUNNEL = "vxlan"; | ||
| 38 | 40 | ||
| 39 | - // TODO: Please change these valuses following the way vrouter is implemented | 41 | + public static final String DEFAULT_GATEWAY_MAC_STR = "fe:00:00:00:00:02"; |
| 40 | - public static final MacAddress GW_EXT_INT_MAC = MacAddress.valueOf("56:e6:30:a6:8c:e5"); | 42 | + public static final MacAddress DEFAULT_GATEWAY_MAC = MacAddress.valueOf(DEFAULT_GATEWAY_MAC_STR); |
| 41 | - public static final MacAddress PHY_ROUTER_MAC = MacAddress.valueOf("00:00:00:00:01:01"); | 43 | + // TODO make this configurable |
| 44 | + public static final MacAddress DEFAULT_EXTERNAL_ROUTER_MAC = MacAddress.valueOf("fe:00:00:00:00:01"); | ||
| 42 | 45 | ||
| 43 | public static final Ip4Address DNS_SERVER_IP = Ip4Address.valueOf("8.8.8.8"); | 46 | public static final Ip4Address DNS_SERVER_IP = Ip4Address.valueOf("8.8.8.8"); |
| 44 | public static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0"); | 47 | public static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0"); |
| 45 | public static final int DHCP_INFINITE_LEASE = -1; | 48 | public static final int DHCP_INFINITE_LEASE = -1; |
| 46 | 49 | ||
| 47 | public static final String NETWORK_ID = "networkId"; | 50 | public static final String NETWORK_ID = "networkId"; |
| 51 | + public static final String SUBNET_ID = "subnetId"; | ||
| 48 | public static final String PORT_ID = "portId"; | 52 | public static final String PORT_ID = "portId"; |
| 49 | public static final String VXLAN_ID = "vxlanId"; | 53 | public static final String VXLAN_ID = "vxlanId"; |
| 50 | public static final String TENANT_ID = "tenantId"; | 54 | public static final String TENANT_ID = "tenantId"; |
| ... | @@ -55,4 +59,8 @@ public final class Constants { | ... | @@ -55,4 +59,8 @@ public final class Constants { |
| 55 | public static final int TUNNELTAG_RULE_PRIORITY = 30000; | 59 | public static final int TUNNELTAG_RULE_PRIORITY = 30000; |
| 56 | public static final int ACL_RULE_PRIORITY = 30000; | 60 | public static final int ACL_RULE_PRIORITY = 30000; |
| 57 | 61 | ||
| 62 | + public static final int ROUTING_RULE_PRIORITY = 25000; | ||
| 63 | + public static final int FLOATING_RULE_PRIORITY = 42000; | ||
| 64 | + public static final int PNAT_RULE_PRIORITY = 26000; | ||
| 65 | + public static final int PNAT_TIMEOUT = 120; | ||
| 58 | } | 66 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present 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.openstacknetworking; | ||
| 17 | + | ||
| 18 | +import org.onosproject.openstackinterface.OpenstackFloatingIP; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * Handles floating IP update requests from OpenStack. | ||
| 22 | + */ | ||
| 23 | +public interface OpenstackFloatingIpService { | ||
| 24 | + | ||
| 25 | + enum Action { | ||
| 26 | + ASSOCIATE, | ||
| 27 | + DISSASSOCIATE | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Handles floating IP create request from OpenStack. | ||
| 32 | + * | ||
| 33 | + * @param floatingIp floating IP information | ||
| 34 | + */ | ||
| 35 | + void createFloatingIp(OpenstackFloatingIP floatingIp); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * Handles floating IP update request from OpenStack. | ||
| 39 | + * | ||
| 40 | + * @param floatingIp floating IP information | ||
| 41 | + */ | ||
| 42 | + void updateFloatingIp(OpenstackFloatingIP floatingIp); | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Handles floating IP remove request from OpenStack. | ||
| 46 | + * | ||
| 47 | + * @param floatingIpId floating ip identifier | ||
| 48 | + */ | ||
| 49 | + void deleteFloatingIp(String floatingIpId); | ||
| 50 | +} |
| ... | @@ -15,76 +15,49 @@ | ... | @@ -15,76 +15,49 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.openstacknetworking; | 16 | package org.onosproject.openstacknetworking; |
| 17 | 17 | ||
| 18 | -import org.onosproject.openstackinterface.OpenstackFloatingIP; | ||
| 19 | import org.onosproject.openstackinterface.OpenstackRouter; | 18 | import org.onosproject.openstackinterface.OpenstackRouter; |
| 20 | import org.onosproject.openstackinterface.OpenstackRouterInterface; | 19 | import org.onosproject.openstackinterface.OpenstackRouterInterface; |
| 21 | 20 | ||
| 22 | /** | 21 | /** |
| 23 | - * Supports L3 management REST API for openstack. | 22 | + * Handles router update requests from OpenStack. |
| 24 | */ | 23 | */ |
| 25 | public interface OpenstackRoutingService { | 24 | public interface OpenstackRoutingService { |
| 26 | 25 | ||
| 27 | /** | 26 | /** |
| 28 | - * Stores the floating IP information created by openstack. | 27 | + * Handles the router create request from OpenStack. |
| 29 | * | 28 | * |
| 30 | - * @param openstackFloatingIp Floating IP information | 29 | + * @param osRouter router information |
| 31 | */ | 30 | */ |
| 32 | - void createFloatingIP(OpenstackFloatingIP openstackFloatingIp); | 31 | + void createRouter(OpenstackRouter osRouter); |
| 33 | 32 | ||
| 34 | /** | 33 | /** |
| 35 | - * Updates flow rules corresponding to the floating IP information updated by openstack. | 34 | + * Handles the router update request from OpenStack. |
| 35 | + * Update router is called when the name, administrative state, or the external | ||
| 36 | + * gateway setting is updated. The external gateway update is the only case | ||
| 37 | + * that openstack routing service cares. | ||
| 36 | * | 38 | * |
| 37 | - * @param openstackFloatingIp Floating IP information | 39 | + * @param osRouter router information |
| 38 | */ | 40 | */ |
| 39 | - void updateFloatingIP(OpenstackFloatingIP openstackFloatingIp); | 41 | + void updateRouter(OpenstackRouter osRouter); |
| 40 | 42 | ||
| 41 | /** | 43 | /** |
| 42 | - * Removes flow rules corresponding to floating IP information removed by openstack. | 44 | + * Handles the router remove request from OpenStack. |
| 43 | * | 45 | * |
| 44 | - * @param id Deleted Floating IP`s ID | 46 | + * @param osRouterId identifier of the router |
| 45 | */ | 47 | */ |
| 46 | - void deleteFloatingIP(String id); | 48 | + void removeRouter(String osRouterId); |
| 47 | 49 | ||
| 48 | /** | 50 | /** |
| 49 | - * Stores the router information created by openstack. | 51 | + * Handles router interface add request from OpenStack. |
| 50 | * | 52 | * |
| 51 | - * @param openstackRouter Router information | 53 | + * @param osInterface router interface information |
| 52 | */ | 54 | */ |
| 53 | - void createRouter(OpenstackRouter openstackRouter); | 55 | + void addRouterInterface(OpenstackRouterInterface osInterface); |
| 54 | 56 | ||
| 55 | /** | 57 | /** |
| 56 | - * Updates flow rules corresponding to the router information updated by openstack. | 58 | + * Handles router interface remove request from OpenStack. |
| 57 | * | 59 | * |
| 58 | - * @param openstackRouter Router information | 60 | + * @param osInterface router interface information |
| 59 | */ | 61 | */ |
| 60 | - void updateRouter(OpenstackRouter openstackRouter); | 62 | + void removeRouterInterface(OpenstackRouterInterface osInterface); |
| 61 | - | ||
| 62 | - /** | ||
| 63 | - * Removes flow rules corresponding to the router information removed by openstack. | ||
| 64 | - * | ||
| 65 | - * @param id Deleted router`s ID | ||
| 66 | - */ | ||
| 67 | - void deleteRouter(String id); | ||
| 68 | - | ||
| 69 | - /** | ||
| 70 | - * Updates flow rules corresponding to the router information updated by openstack. | ||
| 71 | - * | ||
| 72 | - * @param openstackRouterInterface Router interface information | ||
| 73 | - */ | ||
| 74 | - void updateRouterInterface(OpenstackRouterInterface openstackRouterInterface); | ||
| 75 | - | ||
| 76 | - /** | ||
| 77 | - * Removes flow rules corresponding to the router information removed by openstack. | ||
| 78 | - * | ||
| 79 | - * @param openstackRouterInterface Router interface information | ||
| 80 | - */ | ||
| 81 | - void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface); | ||
| 82 | - | ||
| 83 | - /** | ||
| 84 | - * Returns network id for routerInterface. | ||
| 85 | - * | ||
| 86 | - * @param portId routerInterface`s port id | ||
| 87 | - * @return network id | ||
| 88 | - */ | ||
| 89 | - String networkIdForRouterInterface(String portId); | ||
| 90 | } | 63 | } | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016-present 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.openstacknetworking; | ||
| 17 | + | ||
| 18 | +import org.onlab.packet.Ip4Address; | ||
| 19 | +import org.onosproject.core.ApplicationId; | ||
| 20 | +import org.onosproject.net.Device; | ||
| 21 | +import org.onosproject.net.DeviceId; | ||
| 22 | +import org.onosproject.net.behaviour.ExtensionTreatmentResolver; | ||
| 23 | +import org.onosproject.net.device.DeviceService; | ||
| 24 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 25 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 26 | +import org.onosproject.net.flow.instructions.ExtensionPropertyException; | ||
| 27 | +import org.onosproject.net.flow.instructions.ExtensionTreatment; | ||
| 28 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
| 29 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 30 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
| 31 | +import org.slf4j.Logger; | ||
| 32 | + | ||
| 33 | +import static org.onosproject.net.flow.instructions.ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST; | ||
| 34 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * Provides common methods to help populating flow rules for SONA applications. | ||
| 38 | + */ | ||
| 39 | +public final class RulePopulatorUtil { | ||
| 40 | + | ||
| 41 | + protected static final Logger log = getLogger(RulePopulatorUtil.class); | ||
| 42 | + | ||
| 43 | + private static final String TUNNEL_DST = "tunnelDst"; | ||
| 44 | + | ||
| 45 | + private RulePopulatorUtil() { | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Returns tunnel destination extension treatment object. | ||
| 50 | + * | ||
| 51 | + * @param deviceService driver service | ||
| 52 | + * @param deviceId device id to apply this treatment | ||
| 53 | + * @param remoteIp tunnel destination ip address | ||
| 54 | + * @return extension treatment | ||
| 55 | + */ | ||
| 56 | + public static ExtensionTreatment buildExtension(DeviceService deviceService, | ||
| 57 | + DeviceId deviceId, | ||
| 58 | + Ip4Address remoteIp) { | ||
| 59 | + Device device = deviceService.getDevice(deviceId); | ||
| 60 | + if (device != null && !device.is(ExtensionTreatmentResolver.class)) { | ||
| 61 | + log.error("The extension treatment is not supported"); | ||
| 62 | + return null; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + ExtensionTreatmentResolver resolver = device.as(ExtensionTreatmentResolver.class); | ||
| 66 | + ExtensionTreatment treatment = resolver.getExtensionInstruction(NICIRA_SET_TUNNEL_DST.type()); | ||
| 67 | + try { | ||
| 68 | + treatment.setPropertyValue(TUNNEL_DST, remoteIp); | ||
| 69 | + return treatment; | ||
| 70 | + } catch (ExtensionPropertyException e) { | ||
| 71 | + log.warn("Failed to get tunnelDst extension treatment for {}", deviceId); | ||
| 72 | + return null; | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * Removes flow rules with the supplied information. | ||
| 78 | + * | ||
| 79 | + * @param flowObjectiveService flow objective service | ||
| 80 | + * @param appId application id | ||
| 81 | + * @param deviceId device id to remove this flow rule | ||
| 82 | + * @param selector traffic selector | ||
| 83 | + * @param flag flag | ||
| 84 | + * @param priority priority | ||
| 85 | + */ | ||
| 86 | + public static void removeRule(FlowObjectiveService flowObjectiveService, | ||
| 87 | + ApplicationId appId, | ||
| 88 | + DeviceId deviceId, | ||
| 89 | + TrafficSelector selector, | ||
| 90 | + ForwardingObjective.Flag flag, | ||
| 91 | + int priority) { | ||
| 92 | + ForwardingObjective fo = DefaultForwardingObjective.builder() | ||
| 93 | + .withSelector(selector) | ||
| 94 | + .withTreatment(DefaultTrafficTreatment.builder().build()) | ||
| 95 | + .withFlag(flag) | ||
| 96 | + .withPriority(priority) | ||
| 97 | + .fromApp(appId) | ||
| 98 | + .remove(); | ||
| 99 | + | ||
| 100 | + flowObjectiveService.forward(deviceId, fo); | ||
| 101 | + } | ||
| 102 | +} |
| 1 | -/* | ||
| 2 | - * Copyright 2016-present 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.openstacknetworking.routing; | ||
| 17 | - | ||
| 18 | -import org.onosproject.net.Host; | ||
| 19 | -import org.onosproject.openstackinterface.OpenstackFloatingIP; | ||
| 20 | - | ||
| 21 | -/** | ||
| 22 | - * Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes. | ||
| 23 | - */ | ||
| 24 | -public class OpenstackFloatingIPHandler implements Runnable { | ||
| 25 | - | ||
| 26 | - public enum Action { | ||
| 27 | - ASSOCIATE, | ||
| 28 | - DISSASSOCIATE | ||
| 29 | - } | ||
| 30 | - | ||
| 31 | - private final OpenstackFloatingIP floatingIP; | ||
| 32 | - private final OpenstackRoutingRulePopulator rulePopulator; | ||
| 33 | - private final Host host; | ||
| 34 | - private final Action action; | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator, | ||
| 38 | - OpenstackFloatingIP openstackFloatingIP, Action action, Host host) { | ||
| 39 | - this.floatingIP = openstackFloatingIP; | ||
| 40 | - this.rulePopulator = rulePopulator; | ||
| 41 | - this.action = action; | ||
| 42 | - this.host = host; | ||
| 43 | - } | ||
| 44 | - | ||
| 45 | - @Override | ||
| 46 | - public void run() { | ||
| 47 | - if (action == Action.ASSOCIATE) { | ||
| 48 | - rulePopulator.populateFloatingIpRules(floatingIP); | ||
| 49 | - } else { | ||
| 50 | - rulePopulator.removeFloatingIpRules(floatingIP, host); | ||
| 51 | - } | ||
| 52 | - } | ||
| 53 | -} |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -15,99 +15,74 @@ | ... | @@ -15,99 +15,74 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.openstacknetworking.routing; | 16 | package org.onosproject.openstacknetworking.routing; |
| 17 | 17 | ||
| 18 | -import com.google.common.collect.Lists; | 18 | +import org.apache.felix.scr.annotations.Activate; |
| 19 | +import org.apache.felix.scr.annotations.Component; | ||
| 20 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 21 | +import org.apache.felix.scr.annotations.Reference; | ||
| 22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 19 | import org.onlab.packet.ARP; | 23 | import org.onlab.packet.ARP; |
| 20 | -import org.onlab.packet.EthType; | ||
| 21 | import org.onlab.packet.Ethernet; | 24 | import org.onlab.packet.Ethernet; |
| 22 | import org.onlab.packet.Ip4Address; | 25 | import org.onlab.packet.Ip4Address; |
| 23 | import org.onlab.packet.IpAddress; | 26 | import org.onlab.packet.IpAddress; |
| 24 | import org.onlab.packet.MacAddress; | 27 | import org.onlab.packet.MacAddress; |
| 25 | -import org.onosproject.core.ApplicationId; | ||
| 26 | -import org.onosproject.net.DeviceId; | ||
| 27 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 29 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 30 | import org.onosproject.net.flow.TrafficTreatment; | 29 | import org.onosproject.net.flow.TrafficTreatment; |
| 31 | import org.onosproject.net.packet.DefaultOutboundPacket; | 30 | import org.onosproject.net.packet.DefaultOutboundPacket; |
| 31 | +import org.onosproject.net.packet.InboundPacket; | ||
| 32 | import org.onosproject.net.packet.PacketContext; | 32 | import org.onosproject.net.packet.PacketContext; |
| 33 | -import org.onosproject.net.packet.PacketPriority; | 33 | +import org.onosproject.net.packet.PacketProcessor; |
| 34 | import org.onosproject.net.packet.PacketService; | 34 | import org.onosproject.net.packet.PacketService; |
| 35 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 35 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
| 36 | import org.onosproject.openstackinterface.OpenstackPort; | 36 | import org.onosproject.openstackinterface.OpenstackPort; |
| 37 | import org.onosproject.scalablegateway.api.ScalableGatewayService; | 37 | import org.onosproject.scalablegateway.api.ScalableGatewayService; |
| 38 | import org.onosproject.openstacknetworking.Constants; | 38 | import org.onosproject.openstacknetworking.Constants; |
| 39 | -import org.onosproject.openstacknode.OpenstackNodeService; | ||
| 40 | import org.slf4j.Logger; | 39 | import org.slf4j.Logger; |
| 41 | 40 | ||
| 42 | import java.nio.ByteBuffer; | 41 | import java.nio.ByteBuffer; |
| 43 | -import java.util.List; | 42 | +import java.util.concurrent.ExecutorService; |
| 44 | -import java.util.Optional; | ||
| 45 | 43 | ||
| 46 | -import static com.google.common.base.Preconditions.checkNotNull; | 44 | +import static java.util.concurrent.Executors.newSingleThreadExecutor; |
| 45 | +import static org.onlab.util.Tools.groupedThreads; | ||
| 46 | +import static org.onosproject.openstacknetworking.Constants.DEVICE_OWNER_FLOATING_IP; | ||
| 47 | +import static org.onosproject.openstacknetworking.Constants.DEVICE_OWNER_ROUTER_GATEWAY; | ||
| 47 | import static org.slf4j.LoggerFactory.getLogger; | 48 | import static org.slf4j.LoggerFactory.getLogger; |
| 48 | 49 | ||
| 49 | /** | 50 | /** |
| 50 | - * Handle ARP packet sent from Openstack Gateway nodes. | 51 | + * Handle ARP, ICMP and NAT packets from gateway nodes. |
| 51 | */ | 52 | */ |
| 53 | +@Component(immediate = true) | ||
| 52 | public class OpenstackRoutingArpHandler { | 54 | public class OpenstackRoutingArpHandler { |
| 53 | - protected final Logger log = getLogger(getClass()); | 55 | + private final Logger log = getLogger(getClass()); |
| 54 | 56 | ||
| 55 | - private final PacketService packetService; | 57 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 56 | - private final OpenstackInterfaceService openstackService; | 58 | + protected PacketService packetService; |
| 57 | - private final ScalableGatewayService gatewayService; | ||
| 58 | - private final OpenstackNodeService nodeService; | ||
| 59 | - private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway"; | ||
| 60 | - private static final String NETWORK_FLOATING_IP = "network:floatingip"; | ||
| 61 | 59 | ||
| 62 | - /** | 60 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 63 | - * Default constructor. | 61 | + protected OpenstackInterfaceService openstackService; |
| 64 | - * | ||
| 65 | - * @param packetService packet service | ||
| 66 | - * @param openstackService openstackInterface service | ||
| 67 | - * @param gatewayService gateway service | ||
| 68 | - * @param nodeService openstackNodeService | ||
| 69 | - */ | ||
| 70 | - OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService, | ||
| 71 | - OpenstackNodeService nodeService, ScalableGatewayService gatewayService) { | ||
| 72 | - this.packetService = packetService; | ||
| 73 | - this.openstackService = checkNotNull(openstackService); | ||
| 74 | - this.nodeService = nodeService; | ||
| 75 | - this.gatewayService = gatewayService; | ||
| 76 | - } | ||
| 77 | 62 | ||
| 78 | - /** | 63 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 79 | - * Requests ARP packet to GatewayNode. | 64 | + protected ScalableGatewayService gatewayService; |
| 80 | - * | ||
| 81 | - * @param appId application id | ||
| 82 | - */ | ||
| 83 | - public void requestPacket(ApplicationId appId) { | ||
| 84 | 65 | ||
| 85 | - TrafficSelector arpSelector = DefaultTrafficSelector.builder() | 66 | + private final ExecutorService executorService = |
| 86 | - .matchEthType(EthType.EtherType.ARP.ethType().toShort()) | 67 | + newSingleThreadExecutor(groupedThreads("onos/openstackrouting", "packet-event", log)); |
| 87 | - .build(); | ||
| 88 | 68 | ||
| 89 | - getExternalInfo().forEach(deviceId -> | 69 | + private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); |
| 90 | - packetService.requestPackets(arpSelector, | ||
| 91 | - PacketPriority.CONTROL, | ||
| 92 | - appId, | ||
| 93 | - Optional.of(deviceId)) | ||
| 94 | - ); | ||
| 95 | - } | ||
| 96 | 70 | ||
| 97 | - /** | 71 | + @Activate |
| 98 | - * Handles ARP packet. | 72 | + protected void activate() { |
| 99 | - * | 73 | + packetService.addProcessor(packetProcessor, PacketProcessor.director(1)); |
| 100 | - * @param context packet context | 74 | + log.info("Started"); |
| 101 | - * @param ethernet ethernet | 75 | + } |
| 102 | - */ | ||
| 103 | - public void processArpPacketFromRouter(PacketContext context, Ethernet ethernet) { | ||
| 104 | - checkNotNull(context, "context can not be null"); | ||
| 105 | - checkNotNull(ethernet, "ethernet can not be null"); | ||
| 106 | 76 | ||
| 77 | + @Deactivate | ||
| 78 | + protected void deactivate() { | ||
| 79 | + packetService.removeProcessor(packetProcessor); | ||
| 80 | + log.info("Stopped"); | ||
| 81 | + } | ||
| 107 | 82 | ||
| 83 | + private void processArpPacket(PacketContext context, Ethernet ethernet) { | ||
| 108 | ARP arp = (ARP) ethernet.getPayload(); | 84 | ARP arp = (ARP) ethernet.getPayload(); |
| 109 | - | 85 | + log.trace("arpEvent called from {} to {}", |
| 110 | - log.debug("arpEvent called from {} to {}", | ||
| 111 | Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(), | 86 | Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(), |
| 112 | Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString()); | 87 | Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString()); |
| 113 | 88 | ||
| ... | @@ -116,13 +91,11 @@ public class OpenstackRoutingArpHandler { | ... | @@ -116,13 +91,11 @@ public class OpenstackRoutingArpHandler { |
| 116 | } | 91 | } |
| 117 | 92 | ||
| 118 | IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress()); | 93 | IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress()); |
| 119 | - | ||
| 120 | if (getTargetMacForTargetIp(targetIp.getIp4Address()) == MacAddress.NONE) { | 94 | if (getTargetMacForTargetIp(targetIp.getIp4Address()) == MacAddress.NONE) { |
| 121 | return; | 95 | return; |
| 122 | } | 96 | } |
| 123 | - // FIXME: Set the correct gateway | ||
| 124 | - MacAddress targetMac = Constants.GW_EXT_INT_MAC; | ||
| 125 | 97 | ||
| 98 | + MacAddress targetMac = Constants.DEFAULT_EXTERNAL_ROUTER_MAC; | ||
| 126 | Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), | 99 | Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), |
| 127 | targetMac, ethernet); | 100 | targetMac, ethernet); |
| 128 | 101 | ||
| ... | @@ -136,22 +109,35 @@ public class OpenstackRoutingArpHandler { | ... | @@ -136,22 +109,35 @@ public class OpenstackRoutingArpHandler { |
| 136 | ByteBuffer.wrap(ethReply.serialize()))); | 109 | ByteBuffer.wrap(ethReply.serialize()))); |
| 137 | } | 110 | } |
| 138 | 111 | ||
| 112 | + private class InternalPacketProcessor implements PacketProcessor { | ||
| 113 | + | ||
| 114 | + @Override | ||
| 115 | + public void process(PacketContext context) { | ||
| 116 | + if (context.isHandled()) { | ||
| 117 | + return; | ||
| 118 | + } else if (!gatewayService.getGatewayDeviceIds().contains( | ||
| 119 | + context.inPacket().receivedFrom().deviceId())) { | ||
| 120 | + // return if the packet is not from gateway nodes | ||
| 121 | + return; | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + InboundPacket pkt = context.inPacket(); | ||
| 125 | + Ethernet ethernet = pkt.parsed(); | ||
| 126 | + if (ethernet != null && | ||
| 127 | + ethernet.getEtherType() == Ethernet.TYPE_ARP) { | ||
| 128 | + executorService.execute(() -> processArpPacket(context, ethernet)); | ||
| 129 | + } | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + // TODO make a cache for the MAC, not a good idea to REST call every time it gets ARP request | ||
| 139 | private MacAddress getTargetMacForTargetIp(Ip4Address targetIp) { | 134 | private MacAddress getTargetMacForTargetIp(Ip4Address targetIp) { |
| 140 | OpenstackPort port = openstackService.ports().stream() | 135 | OpenstackPort port = openstackService.ports().stream() |
| 141 | - .filter(p -> p.deviceOwner().equals(NETWORK_ROUTER_GATEWAY) || | 136 | + .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_GATEWAY) || |
| 142 | - p.deviceOwner().equals(NETWORK_FLOATING_IP)) | 137 | + p.deviceOwner().equals(DEVICE_OWNER_FLOATING_IP)) |
| 143 | .filter(p -> p.fixedIps().containsValue(targetIp.getIp4Address())) | 138 | .filter(p -> p.fixedIps().containsValue(targetIp.getIp4Address())) |
| 144 | .findAny().orElse(null); | 139 | .findAny().orElse(null); |
| 145 | 140 | ||
| 146 | - if (port == null) { | 141 | + return port == null ? MacAddress.NONE : port.macAddress(); |
| 147 | - return MacAddress.NONE; | ||
| 148 | - } | ||
| 149 | - return port.macAddress(); | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - private List<DeviceId> getExternalInfo() { | ||
| 153 | - List<DeviceId> externalInfoList = Lists.newArrayList(); | ||
| 154 | - gatewayService.getGatewayDeviceIds().forEach(externalInfoList::add); | ||
| 155 | - return externalInfoList; | ||
| 156 | } | 142 | } |
| 157 | } | 143 | } | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | /** | 17 | /** |
| 18 | - * Application for OpenstackRouting. | 18 | + * Implements OpenStack L3 service plugin, which routes packets between subnets, |
| 19 | + * forwards packets from internal networks to external ones, and accesses instances | ||
| 20 | + * from external networks through floating IPs. | ||
| 19 | */ | 21 | */ |
| 20 | package org.onosproject.openstacknetworking.routing; | 22 | package org.onosproject.openstacknetworking.routing; | ... | ... |
| ... | @@ -30,6 +30,7 @@ import org.onlab.packet.Ip4Address; | ... | @@ -30,6 +30,7 @@ import org.onlab.packet.Ip4Address; |
| 30 | import org.onlab.packet.IpPrefix; | 30 | import org.onlab.packet.IpPrefix; |
| 31 | import org.onlab.packet.TpPort; | 31 | import org.onlab.packet.TpPort; |
| 32 | import org.onlab.util.Tools; | 32 | import org.onlab.util.Tools; |
| 33 | +import org.onosproject.core.ApplicationId; | ||
| 33 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
| 34 | import org.onosproject.net.Host; | 35 | import org.onosproject.net.Host; |
| 35 | import org.onosproject.net.flow.DefaultTrafficSelector; | 36 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| ... | @@ -43,6 +44,7 @@ import org.onosproject.openstackinterface.OpenstackPort; | ... | @@ -43,6 +44,7 @@ import org.onosproject.openstackinterface.OpenstackPort; |
| 43 | import org.onosproject.openstackinterface.OpenstackSecurityGroup; | 44 | import org.onosproject.openstackinterface.OpenstackSecurityGroup; |
| 44 | import org.onosproject.openstackinterface.OpenstackSecurityGroupRule; | 45 | import org.onosproject.openstackinterface.OpenstackSecurityGroupRule; |
| 45 | import org.onosproject.openstacknetworking.OpenstackSecurityGroupService; | 46 | import org.onosproject.openstacknetworking.OpenstackSecurityGroupService; |
| 47 | +import org.onosproject.openstacknetworking.AbstractVmHandler; | ||
| 46 | import org.slf4j.Logger; | 48 | import org.slf4j.Logger; |
| 47 | import org.slf4j.LoggerFactory; | 49 | import org.slf4j.LoggerFactory; |
| 48 | 50 | ||
| ... | @@ -60,7 +62,7 @@ import static org.onosproject.openstacknetworking.Constants.*; | ... | @@ -60,7 +62,7 @@ import static org.onosproject.openstacknetworking.Constants.*; |
| 60 | */ | 62 | */ |
| 61 | @Component(immediate = true) | 63 | @Component(immediate = true) |
| 62 | @Service | 64 | @Service |
| 63 | -public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler | 65 | +public class OpenstackSecurityGroupManager extends AbstractVmHandler |
| 64 | implements OpenstackSecurityGroupService { | 66 | implements OpenstackSecurityGroupService { |
| 65 | 67 | ||
| 66 | private final Logger log = LoggerFactory.getLogger(getClass()); | 68 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| ... | @@ -77,10 +79,12 @@ public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler | ... | @@ -77,10 +79,12 @@ public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler |
| 77 | private static final String ETHTYPE_IPV4 = "IPV4"; | 79 | private static final String ETHTYPE_IPV4 = "IPV4"; |
| 78 | 80 | ||
| 79 | private final Map<Host, Set<SecurityGroupRule>> securityGroupRuleMap = Maps.newConcurrentMap(); | 81 | private final Map<Host, Set<SecurityGroupRule>> securityGroupRuleMap = Maps.newConcurrentMap(); |
| 82 | + private ApplicationId appId; | ||
| 80 | 83 | ||
| 81 | @Activate | 84 | @Activate |
| 82 | protected void activate() { | 85 | protected void activate() { |
| 83 | super.activate(); | 86 | super.activate(); |
| 87 | + appId = coreService.registerApplication(SWITCHING_APP_ID); | ||
| 84 | } | 88 | } |
| 85 | 89 | ||
| 86 | @Deactivate | 90 | @Deactivate |
| ... | @@ -96,7 +100,7 @@ public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler | ... | @@ -96,7 +100,7 @@ public class OpenstackSecurityGroupRulePopulator extends AbstractVmHandler |
| 96 | 100 | ||
| 97 | Optional<Host> host = getVmByPortId(osPort.id()); | 101 | Optional<Host> host = getVmByPortId(osPort.id()); |
| 98 | if (!host.isPresent()) { | 102 | if (!host.isPresent()) { |
| 99 | - log.warn("No host found with {}", osPort); | 103 | + log.debug("No host found with {}", osPort.id()); |
| 100 | return; | 104 | return; |
| 101 | } | 105 | } |
| 102 | eventExecutor.execute(() -> updateSecurityGroupRules(host.get(), true)); | 106 | eventExecutor.execute(() -> updateSecurityGroupRules(host.get(), true)); | ... | ... |
| ... | @@ -40,6 +40,7 @@ import org.onosproject.net.packet.PacketService; | ... | @@ -40,6 +40,7 @@ import org.onosproject.net.packet.PacketService; |
| 40 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 40 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
| 41 | import org.onosproject.openstackinterface.OpenstackNetwork; | 41 | import org.onosproject.openstackinterface.OpenstackNetwork; |
| 42 | import org.onosproject.openstackinterface.OpenstackPort; | 42 | import org.onosproject.openstackinterface.OpenstackPort; |
| 43 | +import org.onosproject.openstacknetworking.AbstractVmHandler; | ||
| 43 | import org.osgi.service.component.ComponentContext; | 44 | import org.osgi.service.component.ComponentContext; |
| 44 | import org.slf4j.Logger; | 45 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; | 46 | import org.slf4j.LoggerFactory; |
| ... | @@ -54,12 +55,11 @@ import static org.onosproject.openstacknetworking.Constants.*; | ... | @@ -54,12 +55,11 @@ import static org.onosproject.openstacknetworking.Constants.*; |
| 54 | * Handles ARP packet from VMs. | 55 | * Handles ARP packet from VMs. |
| 55 | */ | 56 | */ |
| 56 | @Component(immediate = true) | 57 | @Component(immediate = true) |
| 57 | -public final class OpenstackArpHandler extends AbstractVmHandler { | 58 | +public final class OpenstackSwitchingArpHandler extends AbstractVmHandler { |
| 58 | 59 | ||
| 59 | private final Logger log = LoggerFactory.getLogger(getClass()); | 60 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 60 | 61 | ||
| 61 | private static final String GATEWAY_MAC = "gatewayMac"; | 62 | private static final String GATEWAY_MAC = "gatewayMac"; |
| 62 | - private static final String DEFAULT_GATEWAY_MAC = "1f:1f:1f:1f:1f:1f"; | ||
| 63 | 63 | ||
| 64 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 64 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 65 | protected PacketService packetService; | 65 | protected PacketService packetService; |
| ... | @@ -67,9 +67,9 @@ public final class OpenstackArpHandler extends AbstractVmHandler { | ... | @@ -67,9 +67,9 @@ public final class OpenstackArpHandler extends AbstractVmHandler { |
| 67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 68 | protected OpenstackInterfaceService openstackService; | 68 | protected OpenstackInterfaceService openstackService; |
| 69 | 69 | ||
| 70 | - @Property(name = GATEWAY_MAC, value = DEFAULT_GATEWAY_MAC, | 70 | + @Property(name = GATEWAY_MAC, value = DEFAULT_GATEWAY_MAC_STR, |
| 71 | label = "Fake MAC address for virtual network subnet gateway") | 71 | label = "Fake MAC address for virtual network subnet gateway") |
| 72 | - private String gatewayMac = DEFAULT_GATEWAY_MAC; | 72 | + private String gatewayMac = DEFAULT_GATEWAY_MAC_STR; |
| 73 | 73 | ||
| 74 | private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); | 74 | private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); |
| 75 | private final Set<Ip4Address> gateways = Sets.newConcurrentHashSet(); | 75 | private final Set<Ip4Address> gateways = Sets.newConcurrentHashSet(); | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -126,7 +126,7 @@ public class OpensatckRouterWebResource extends AbstractWebResource { | ... | @@ -126,7 +126,7 @@ public class OpensatckRouterWebResource extends AbstractWebResource { |
| 126 | 126 | ||
| 127 | OpenstackRoutingService routingService | 127 | OpenstackRoutingService routingService |
| 128 | = getService(OpenstackRoutingService.class); | 128 | = getService(OpenstackRoutingService.class); |
| 129 | - routingService.updateRouterInterface(openstackRouterInterface); | 129 | + routingService.addRouterInterface(openstackRouterInterface); |
| 130 | 130 | ||
| 131 | log.debug("REST API AddRouterInterface is called from router {} portId: {}, subnetId: {}, tenantId: {}", | 131 | log.debug("REST API AddRouterInterface is called from router {} portId: {}, subnetId: {}, tenantId: {}", |
| 132 | openstackRouterInterface.id(), openstackRouterInterface.portId(), | 132 | openstackRouterInterface.id(), openstackRouterInterface.portId(), |
| ... | @@ -147,7 +147,7 @@ public class OpensatckRouterWebResource extends AbstractWebResource { | ... | @@ -147,7 +147,7 @@ public class OpensatckRouterWebResource extends AbstractWebResource { |
| 147 | checkNotNull(id); | 147 | checkNotNull(id); |
| 148 | OpenstackRoutingService routingService | 148 | OpenstackRoutingService routingService |
| 149 | = getService(OpenstackRoutingService.class); | 149 | = getService(OpenstackRoutingService.class); |
| 150 | - routingService.deleteRouter(id); | 150 | + routingService.removeRouter(id); |
| 151 | 151 | ||
| 152 | log.debug("REST API DELETE routers is called {}", id); | 152 | log.debug("REST API DELETE routers is called {}", id); |
| 153 | return Response.noContent().build(); | 153 | return Response.noContent().build(); | ... | ... |
| ... | @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import org.onosproject.openstackinterface.OpenstackFloatingIP; | 21 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
| 22 | import org.onosproject.openstackinterface.web.OpenstackFloatingIpCodec; | 22 | import org.onosproject.openstackinterface.web.OpenstackFloatingIpCodec; |
| 23 | -import org.onosproject.openstacknetworking.OpenstackRoutingService; | 23 | +import org.onosproject.openstacknetworking.OpenstackFloatingIpService; |
| 24 | import org.onosproject.rest.AbstractWebResource; | 24 | import org.onosproject.rest.AbstractWebResource; |
| 25 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; | 26 | import org.slf4j.LoggerFactory; |
| ... | @@ -45,8 +45,7 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -45,8 +45,7 @@ import static com.google.common.base.Preconditions.checkNotNull; |
| 45 | public class OpenstackFloatingIpWebResource extends AbstractWebResource { | 45 | public class OpenstackFloatingIpWebResource extends AbstractWebResource { |
| 46 | private final Logger log = LoggerFactory.getLogger(getClass()); | 46 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 47 | 47 | ||
| 48 | - private static final OpenstackFloatingIpCodec FLOATING_IP_CODEC | 48 | + private static final OpenstackFloatingIpCodec FLOATING_IP_CODEC = new OpenstackFloatingIpCodec(); |
| 49 | - = new OpenstackFloatingIpCodec(); | ||
| 50 | 49 | ||
| 51 | /** | 50 | /** |
| 52 | * Create FloatingIP. | 51 | * Create FloatingIP. |
| ... | @@ -64,20 +63,15 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource { | ... | @@ -64,20 +63,15 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource { |
| 64 | ObjectMapper mapper = new ObjectMapper(); | 63 | ObjectMapper mapper = new ObjectMapper(); |
| 65 | ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input); | 64 | ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input); |
| 66 | 65 | ||
| 67 | - OpenstackFloatingIP osFloatingIp = | 66 | + OpenstackFloatingIP osFloatingIp = FLOATING_IP_CODEC.decode(floatingIpNode, this); |
| 68 | - FLOATING_IP_CODEC.decode(floatingIpNode, this); | 67 | + OpenstackFloatingIpService floatingIpService = |
| 69 | - | 68 | + getService(OpenstackFloatingIpService.class); |
| 70 | - OpenstackRoutingService routingService = | 69 | + floatingIpService.createFloatingIp(osFloatingIp); |
| 71 | - getService(OpenstackRoutingService.class); | ||
| 72 | - | ||
| 73 | - routingService.createFloatingIP(osFloatingIp); | ||
| 74 | 70 | ||
| 75 | log.debug("REST API CREATE floatingip called"); | 71 | log.debug("REST API CREATE floatingip called"); |
| 76 | - | ||
| 77 | return Response.status(Response.Status.OK).build(); | 72 | return Response.status(Response.Status.OK).build(); |
| 78 | } catch (Exception e) { | 73 | } catch (Exception e) { |
| 79 | log.error("createFloatingIp failed with {}", e.toString()); | 74 | log.error("createFloatingIp failed with {}", e.toString()); |
| 80 | - | ||
| 81 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) | 75 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) |
| 82 | .build(); | 76 | .build(); |
| 83 | } | 77 | } |
| ... | @@ -102,20 +96,15 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource { | ... | @@ -102,20 +96,15 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource { |
| 102 | ObjectMapper mapper = new ObjectMapper(); | 96 | ObjectMapper mapper = new ObjectMapper(); |
| 103 | ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input); | 97 | ObjectNode floatingIpNode = (ObjectNode) mapper.readTree(input); |
| 104 | 98 | ||
| 105 | - OpenstackFloatingIP osFloatingIp = | 99 | + OpenstackFloatingIP osFloatingIp = FLOATING_IP_CODEC.decode(floatingIpNode, this); |
| 106 | - FLOATING_IP_CODEC.decode(floatingIpNode, this); | 100 | + OpenstackFloatingIpService floatingIpService = |
| 107 | - | 101 | + getService(OpenstackFloatingIpService.class); |
| 108 | - OpenstackRoutingService routingService = | 102 | + floatingIpService.updateFloatingIp(osFloatingIp); |
| 109 | - getService(OpenstackRoutingService.class); | ||
| 110 | - | ||
| 111 | - routingService.updateFloatingIP(osFloatingIp); | ||
| 112 | 103 | ||
| 113 | log.debug("REST API UPDATE floatingip called {}", id); | 104 | log.debug("REST API UPDATE floatingip called {}", id); |
| 114 | - | ||
| 115 | return Response.status(Response.Status.OK).build(); | 105 | return Response.status(Response.Status.OK).build(); |
| 116 | } catch (Exception e) { | 106 | } catch (Exception e) { |
| 117 | log.error("updateFloatingIp failed with {}", e.toString()); | 107 | log.error("updateFloatingIp failed with {}", e.toString()); |
| 118 | - | ||
| 119 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) | 108 | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) |
| 120 | .build(); | 109 | .build(); |
| 121 | } | 110 | } |
| ... | @@ -133,12 +122,11 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource { | ... | @@ -133,12 +122,11 @@ public class OpenstackFloatingIpWebResource extends AbstractWebResource { |
| 133 | public Response deleteFloatingIp(@PathParam("id") String id) { | 122 | public Response deleteFloatingIp(@PathParam("id") String id) { |
| 134 | checkNotNull(id); | 123 | checkNotNull(id); |
| 135 | 124 | ||
| 136 | - OpenstackRoutingService routingService = | 125 | + OpenstackFloatingIpService floatingIpService = |
| 137 | - getService(OpenstackRoutingService.class); | 126 | + getService(OpenstackFloatingIpService.class); |
| 138 | - routingService.deleteFloatingIP(id); | 127 | + floatingIpService.deleteFloatingIp(id); |
| 139 | 128 | ||
| 140 | log.debug("REST API DELETE floatingip is called {}", id); | 129 | log.debug("REST API DELETE floatingip is called {}", id); |
| 141 | - | ||
| 142 | return Response.noContent().build(); | 130 | return Response.noContent().build(); |
| 143 | } | 131 | } |
| 144 | 132 | ... | ... |
| ... | @@ -79,7 +79,6 @@ public class OpenstackPortWebResource extends AbstractWebResource { | ... | @@ -79,7 +79,6 @@ public class OpenstackPortWebResource extends AbstractWebResource { |
| 79 | sgService.updateSecurityGroup(osPort); | 79 | sgService.updateSecurityGroup(osPort); |
| 80 | 80 | ||
| 81 | return Response.status(Response.Status.OK).build(); | 81 | return Response.status(Response.Status.OK).build(); |
| 82 | - | ||
| 83 | } catch (IOException e) { | 82 | } catch (IOException e) { |
| 84 | log.error("UpdatePort post process failed due to {}", e.getMessage()); | 83 | log.error("UpdatePort post process failed due to {}", e.getMessage()); |
| 85 | 84 | ... | ... |
| ... | @@ -28,6 +28,7 @@ import java.util.Optional; | ... | @@ -28,6 +28,7 @@ import java.util.Optional; |
| 28 | 28 | ||
| 29 | import static com.google.common.base.Preconditions.checkArgument; | 29 | import static com.google.common.base.Preconditions.checkArgument; |
| 30 | import static com.google.common.base.Preconditions.checkNotNull; | 30 | import static com.google.common.base.Preconditions.checkNotNull; |
| 31 | +import static org.onosproject.openstacknode.Constants.PATCH_INTG_BRIDGE; | ||
| 31 | import static org.onosproject.openstacknode.OpenstackNodeEvent.NodeState.INIT; | 32 | import static org.onosproject.openstacknode.OpenstackNodeEvent.NodeState.INIT; |
| 32 | 33 | ||
| 33 | /** | 34 | /** |
| ... | @@ -182,6 +183,20 @@ public final class OpenstackNode { | ... | @@ -182,6 +183,20 @@ public final class OpenstackNode { |
| 182 | return DeviceId.deviceId("ovsdb:" + managementIp.toString()); | 183 | return DeviceId.deviceId("ovsdb:" + managementIp.toString()); |
| 183 | } | 184 | } |
| 184 | 185 | ||
| 186 | + /** | ||
| 187 | + * Returns the name of the port connected to the external network. | ||
| 188 | + * It returns valid value only if the node is gateway node. | ||
| 189 | + * | ||
| 190 | + * @return external port name | ||
| 191 | + */ | ||
| 192 | + public Optional<String> externalPortName() { | ||
| 193 | + if (type == NodeType.GATEWAY) { | ||
| 194 | + return Optional.of(PATCH_INTG_BRIDGE); | ||
| 195 | + } else { | ||
| 196 | + return Optional.empty(); | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + | ||
| 185 | @Override | 200 | @Override |
| 186 | public boolean equals(Object obj) { | 201 | public boolean equals(Object obj) { |
| 187 | if (this == obj) { | 202 | if (this == obj) { | ... | ... |
-
Please register or login to post a comment