Committed by
Gerrit Code Review
[ONOS-3952] Implement FloatingIP Handler for OpenstackRoutingService
- Implements floatingIp REST interfaces & event handler - Implements rulePopulate method for floatingIp handler - Fixes minor logics - Changes app structure - exports configuration - Implements case issue. when openstack deletes vm w/o deassociating floatingIp, openstack doesn`t send floatingIp deassociation event. Change-Id: If4d8ac3fecfed1957d84139f94ae31f593a9097b
Showing
6 changed files
with
43 additions
and
20 deletions
... | @@ -80,5 +80,11 @@ public interface OpenstackRoutingService { | ... | @@ -80,5 +80,11 @@ public interface OpenstackRoutingService { |
80 | */ | 80 | */ |
81 | void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface); | 81 | void removeRouterInterface(OpenstackRouterInterface openstackRouterInterface); |
82 | 82 | ||
83 | - | 83 | + /** |
84 | + * Checks floatingIp deassociation when corresponding deleted vm. | ||
85 | + * | ||
86 | + * @param portId Deleted vm | ||
87 | + * @param portInfo | ||
88 | + */ | ||
89 | + void checkDisassociatedFloatingIp(String portId, OpenstackPortInfo portInfo); | ||
84 | } | 90 | } | ... | ... |
... | @@ -15,20 +15,34 @@ | ... | @@ -15,20 +15,34 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking.routing; | 16 | package org.onosproject.openstacknetworking.routing; |
17 | 17 | ||
18 | - import org.onosproject.event.AbstractEvent; | 18 | +import org.onosproject.openstackinterface.OpenstackFloatingIP; |
19 | +import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes. | 22 | * Handle FloatingIP Event for Managing Flow Rules In Openstack Nodes. |
22 | */ | 23 | */ |
23 | public class OpenstackFloatingIPHandler implements Runnable { | 24 | public class OpenstackFloatingIPHandler implements Runnable { |
24 | 25 | ||
25 | - volatile AbstractEvent event; | 26 | + private final OpenstackFloatingIP floatingIP; |
26 | - OpenstackFloatingIPHandler(AbstractEvent event) { | 27 | + private final OpenstackRoutingRulePopulator rulePopulator; |
27 | - this.event = event; | 28 | + private boolean associate; |
29 | + private final OpenstackPortInfo portInfo; | ||
30 | + | ||
31 | + OpenstackFloatingIPHandler(OpenstackRoutingRulePopulator rulePopulator, | ||
32 | + OpenstackFloatingIP openstackFloatingIP, boolean associate, OpenstackPortInfo portInfo) { | ||
33 | + this.floatingIP = openstackFloatingIP; | ||
34 | + this.rulePopulator = rulePopulator; | ||
35 | + this.associate = associate; | ||
36 | + this.portInfo = portInfo; | ||
28 | } | 37 | } |
29 | 38 | ||
30 | @Override | 39 | @Override |
31 | public void run() { | 40 | public void run() { |
41 | + if (associate) { | ||
42 | + rulePopulator.populateFloatingIpRules(floatingIP); | ||
43 | + } else { | ||
44 | + rulePopulator.removeFloatingIpRules(floatingIP, portInfo); | ||
45 | + } | ||
32 | 46 | ||
33 | } | 47 | } |
34 | } | 48 | } | ... | ... |
... | @@ -56,19 +56,18 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -56,19 +56,18 @@ public class OpenstackPnatHandler implements Runnable { |
56 | private final int portNum; | 56 | private final int portNum; |
57 | private final OpenstackPort openstackPort; | 57 | private final OpenstackPort openstackPort; |
58 | private final Port port; | 58 | private final Port port; |
59 | + private OpenstackRoutingConfig config; | ||
59 | 60 | ||
60 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; | 61 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; |
61 | - // TODO: This will be replaced to get the information from openstacknetworkingservice. | ||
62 | - private static final MacAddress GATEWAYMAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | ||
63 | - private static final MacAddress EXTERNAL_INTERFACE_MAC = MacAddress.valueOf("00:00:00:00:00:11"); | ||
64 | 62 | ||
65 | OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context, | 63 | OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context, |
66 | - int portNum, OpenstackPort openstackPort, Port port) { | 64 | + int portNum, OpenstackPort openstackPort, Port port, OpenstackRoutingConfig config) { |
67 | this.rulePopulator = checkNotNull(rulePopulator); | 65 | this.rulePopulator = checkNotNull(rulePopulator); |
68 | this.context = checkNotNull(context); | 66 | this.context = checkNotNull(context); |
69 | this.portNum = checkNotNull(portNum); | 67 | this.portNum = checkNotNull(portNum); |
70 | this.openstackPort = checkNotNull(openstackPort); | 68 | this.openstackPort = checkNotNull(openstackPort); |
71 | this.port = checkNotNull(port); | 69 | this.port = checkNotNull(port); |
70 | + this.config = checkNotNull(config); | ||
72 | } | 71 | } |
73 | 72 | ||
74 | @Override | 73 | @Override |
... | @@ -85,7 +84,8 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -85,7 +84,8 @@ public class OpenstackPnatHandler implements Runnable { |
85 | OpenstackRouter router = getOpenstackRouter(openstackPort); | 84 | OpenstackRouter router = getOpenstackRouter(openstackPort); |
86 | 85 | ||
87 | rulePopulator.populatePnatFlowRules(inboundPacket, openstackPort, portNum, | 86 | rulePopulator.populatePnatFlowRules(inboundPacket, openstackPort, portNum, |
88 | - getExternalIp(router), getExternalInterfaceMacAddress(), getExternalRouterMacAddress()); | 87 | + getExternalIp(router), MacAddress.valueOf(config.gatewayExternalInterfaceMac()), |
88 | + MacAddress.valueOf(config.physicalRouterMac())); | ||
89 | 89 | ||
90 | packetOut((Ethernet) ethernet.clone(), inboundPacket.receivedFrom().deviceId(), portNum, router); | 90 | packetOut((Ethernet) ethernet.clone(), inboundPacket.receivedFrom().deviceId(), portNum, router); |
91 | } | 91 | } |
... | @@ -144,8 +144,9 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -144,8 +144,9 @@ public class OpenstackPnatHandler implements Runnable { |
144 | iPacket.setSourceAddress(getExternalIp(router).toString()); | 144 | iPacket.setSourceAddress(getExternalIp(router).toString()); |
145 | iPacket.resetChecksum(); | 145 | iPacket.resetChecksum(); |
146 | iPacket.setParent(ethernet); | 146 | iPacket.setParent(ethernet); |
147 | - ethernet.setSourceMACAddress(getExternalInterfaceMacAddress()) | 147 | + ethernet.setPayload(iPacket); |
148 | - .setDestinationMACAddress(getExternalRouterMacAddress()); | 148 | + ethernet.setSourceMACAddress(config.gatewayExternalInterfaceMac()) |
149 | + .setDestinationMACAddress(config.physicalRouterMac()); | ||
149 | ethernet.resetChecksum(); | 150 | ethernet.resetChecksum(); |
150 | 151 | ||
151 | treatment.setOutput(port.number()); | 152 | treatment.setOutput(port.number()); |
... | @@ -153,11 +154,4 @@ public class OpenstackPnatHandler implements Runnable { | ... | @@ -153,11 +154,4 @@ public class OpenstackPnatHandler implements Runnable { |
153 | packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(), | 154 | packetService.emit(new DefaultOutboundPacket(deviceId, treatment.build(), |
154 | ByteBuffer.wrap(ethernet.serialize()))); | 155 | ByteBuffer.wrap(ethernet.serialize()))); |
155 | } | 156 | } |
156 | - | ||
157 | - private MacAddress getExternalInterfaceMacAddress() { | ||
158 | - return EXTERNAL_INTERFACE_MAC; | ||
159 | - } | ||
160 | - private MacAddress getExternalRouterMacAddress() { | ||
161 | - return GATEWAYMAC; | ||
162 | - } | ||
163 | } | 157 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
... | @@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ... | @@ -19,6 +19,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
19 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
20 | import org.onosproject.openstackinterface.OpenstackPort; | 20 | import org.onosproject.openstackinterface.OpenstackPort; |
21 | import org.onosproject.openstackinterface.web.OpenstackPortCodec; | 21 | import org.onosproject.openstackinterface.web.OpenstackPortCodec; |
22 | +import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
23 | +import org.onosproject.openstacknetworking.OpenstackRoutingService; | ||
22 | import org.onosproject.openstacknetworking.OpenstackSwitchingService; | 24 | import org.onosproject.openstacknetworking.OpenstackSwitchingService; |
23 | import org.onosproject.rest.AbstractWebResource; | 25 | import org.onosproject.rest.AbstractWebResource; |
24 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
... | @@ -42,7 +44,7 @@ import java.io.InputStream; | ... | @@ -42,7 +44,7 @@ import java.io.InputStream; |
42 | public class OpenstackPortWebResource extends AbstractWebResource { | 44 | public class OpenstackPortWebResource extends AbstractWebResource { |
43 | 45 | ||
44 | private final Logger log = LoggerFactory.getLogger(getClass()); | 46 | private final Logger log = LoggerFactory.getLogger(getClass()); |
45 | - | 47 | + private static final String PORTNAME_PREFIX_VM = "tap"; |
46 | private static final OpenstackPortCodec PORT_CODEC = new OpenstackPortCodec(); | 48 | private static final OpenstackPortCodec PORT_CODEC = new OpenstackPortCodec(); |
47 | 49 | ||
48 | @POST | 50 | @POST |
... | @@ -75,7 +77,14 @@ public class OpenstackPortWebResource extends AbstractWebResource { | ... | @@ -75,7 +77,14 @@ public class OpenstackPortWebResource extends AbstractWebResource { |
75 | public Response deletePorts(@PathParam("portUUID") String id) { | 77 | public Response deletePorts(@PathParam("portUUID") String id) { |
76 | OpenstackSwitchingService switchingService = | 78 | OpenstackSwitchingService switchingService = |
77 | getService(OpenstackSwitchingService.class); | 79 | getService(OpenstackSwitchingService.class); |
80 | + OpenstackPortInfo portInfo = switchingService.openstackPortInfo() | ||
81 | + .get(PORTNAME_PREFIX_VM.concat(id.substring(0, 11))); | ||
82 | + OpenstackRoutingService routingService = | ||
83 | + getService(OpenstackRoutingService.class); | ||
84 | + routingService.checkDisassociatedFloatingIp(id, portInfo); | ||
85 | + | ||
78 | switchingService.removePort(id); | 86 | switchingService.removePort(id); |
87 | + | ||
79 | return Response.status(Response.Status.OK).build(); | 88 | return Response.status(Response.Status.OK).build(); |
80 | } | 89 | } |
81 | 90 | ... | ... |
-
Please register or login to post a comment