Committed by
Gerrit Code Review
[ONOS-3948] Seperate mgmt and data network in OpenstackSwitching/RoutingService
- Supports the seperation of management and data network Change-Id: I178dbe2af241123c5181f94a7b46fc15b4cb37c7
Showing
10 changed files
with
318 additions
and
226 deletions
... | @@ -15,13 +15,13 @@ | ... | @@ -15,13 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstackinterface; | 16 | package org.onosproject.openstackinterface; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableMap; | ||
18 | import com.google.common.collect.Maps; | 19 | import com.google.common.collect.Maps; |
19 | import org.onlab.packet.Ip4Address; | 20 | import org.onlab.packet.Ip4Address; |
20 | import org.onlab.packet.IpAddress; | 21 | import org.onlab.packet.IpAddress; |
21 | import org.onlab.packet.MacAddress; | 22 | import org.onlab.packet.MacAddress; |
22 | 23 | ||
23 | import java.util.Collection; | 24 | import java.util.Collection; |
24 | -import java.util.HashMap; | ||
25 | import java.util.Map; | 25 | import java.util.Map; |
26 | 26 | ||
27 | import static com.google.common.base.Preconditions.checkNotNull; | 27 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -40,31 +40,31 @@ public final class OpenstackPort { | ... | @@ -40,31 +40,31 @@ public final class OpenstackPort { |
40 | 40 | ||
41 | private PortStatus status; | 41 | private PortStatus status; |
42 | private String name; | 42 | private String name; |
43 | - private Map<IpAddress, MacAddress> allowedAddressPairs; | 43 | + private ImmutableMap<IpAddress, MacAddress> allowedAddressPairs; |
44 | private boolean adminStateUp; | 44 | private boolean adminStateUp; |
45 | private String networkId; | 45 | private String networkId; |
46 | private String tenantId; | 46 | private String tenantId; |
47 | private String deviceOwner; | 47 | private String deviceOwner; |
48 | private MacAddress macAddress; | 48 | private MacAddress macAddress; |
49 | // <subnet id, ip address> | 49 | // <subnet id, ip address> |
50 | - private HashMap<String, Ip4Address> fixedIps; | 50 | + private ImmutableMap<String, Ip4Address> fixedIps; |
51 | private String id; | 51 | private String id; |
52 | private Collection<String> securityGroups; | 52 | private Collection<String> securityGroups; |
53 | private String deviceId; | 53 | private String deviceId; |
54 | 54 | ||
55 | private OpenstackPort(PortStatus status, String name, Map<IpAddress, MacAddress> allowedAddressPairs, | 55 | private OpenstackPort(PortStatus status, String name, Map<IpAddress, MacAddress> allowedAddressPairs, |
56 | boolean adminStateUp, String networkId, String tenantId, | 56 | boolean adminStateUp, String networkId, String tenantId, |
57 | - String deviceOwner, MacAddress macAddress, HashMap fixedIps, | 57 | + String deviceOwner, MacAddress macAddress, Map<String, Ip4Address> fixedIps, |
58 | String id, Collection<String> securityGroups, String deviceId) { | 58 | String id, Collection<String> securityGroups, String deviceId) { |
59 | this.status = status; | 59 | this.status = status; |
60 | this.name = name; | 60 | this.name = name; |
61 | - this.allowedAddressPairs = checkNotNull(allowedAddressPairs); | 61 | + this.allowedAddressPairs = checkNotNull(ImmutableMap.copyOf(allowedAddressPairs)); |
62 | this.adminStateUp = adminStateUp; | 62 | this.adminStateUp = adminStateUp; |
63 | this.networkId = checkNotNull(networkId); | 63 | this.networkId = checkNotNull(networkId); |
64 | this.tenantId = checkNotNull(tenantId); | 64 | this.tenantId = checkNotNull(tenantId); |
65 | this.deviceOwner = deviceOwner; | 65 | this.deviceOwner = deviceOwner; |
66 | this.macAddress = checkNotNull(macAddress); | 66 | this.macAddress = checkNotNull(macAddress); |
67 | - this.fixedIps = checkNotNull(fixedIps); | 67 | + this.fixedIps = checkNotNull(ImmutableMap.copyOf(fixedIps)); |
68 | this.id = checkNotNull(id); | 68 | this.id = checkNotNull(id); |
69 | this.securityGroups = securityGroups; | 69 | this.securityGroups = securityGroups; |
70 | this.deviceId = deviceId; | 70 | this.deviceId = deviceId; |
... | @@ -149,7 +149,7 @@ public final class OpenstackPort { | ... | @@ -149,7 +149,7 @@ public final class OpenstackPort { |
149 | * | 149 | * |
150 | * @return fixed IP info | 150 | * @return fixed IP info |
151 | */ | 151 | */ |
152 | - public HashMap fixedIps() { | 152 | + public Map<String, Ip4Address> fixedIps() { |
153 | return fixedIps; | 153 | return fixedIps; |
154 | } | 154 | } |
155 | 155 | ||
... | @@ -194,7 +194,7 @@ public final class OpenstackPort { | ... | @@ -194,7 +194,7 @@ public final class OpenstackPort { |
194 | private String deviceOwner; | 194 | private String deviceOwner; |
195 | private MacAddress macAddress; | 195 | private MacAddress macAddress; |
196 | // list of hash map <subnet id, ip address> | 196 | // list of hash map <subnet id, ip address> |
197 | - private HashMap<String, Ip4Address> fixedIps; | 197 | + private Map<String, Ip4Address> fixedIps; |
198 | private String id; | 198 | private String id; |
199 | private Collection<String> securityGroups; | 199 | private Collection<String> securityGroups; |
200 | private String deviceId; | 200 | private String deviceId; |
... | @@ -305,7 +305,7 @@ public final class OpenstackPort { | ... | @@ -305,7 +305,7 @@ public final class OpenstackPort { |
305 | * @param fixedIpList Fixed IP info | 305 | * @param fixedIpList Fixed IP info |
306 | * @return Builder object | 306 | * @return Builder object |
307 | */ | 307 | */ |
308 | - public Builder fixedIps(HashMap<String, Ip4Address> fixedIpList) { | 308 | + public Builder fixedIps(Map<String, Ip4Address> fixedIpList) { |
309 | fixedIps.putAll(fixedIpList); | 309 | fixedIps.putAll(fixedIpList); |
310 | 310 | ||
311 | return this; | 311 | return this; | ... | ... |
... | @@ -30,7 +30,6 @@ import org.slf4j.Logger; | ... | @@ -30,7 +30,6 @@ import org.slf4j.Logger; |
30 | import org.slf4j.LoggerFactory; | 30 | import org.slf4j.LoggerFactory; |
31 | 31 | ||
32 | import java.util.Collection; | 32 | import java.util.Collection; |
33 | -import java.util.HashMap; | ||
34 | import java.util.Map; | 33 | import java.util.Map; |
35 | 34 | ||
36 | import static com.google.common.base.Preconditions.checkNotNull; | 35 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -64,7 +63,7 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { | ... | @@ -64,7 +63,7 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { |
64 | public OpenstackPort decode(ObjectNode json, CodecContext context) { | 63 | public OpenstackPort decode(ObjectNode json, CodecContext context) { |
65 | 64 | ||
66 | checkNotNull(json); | 65 | checkNotNull(json); |
67 | - HashMap<String, Ip4Address> fixedIpMap = new HashMap<>(); | 66 | + Map<String, Ip4Address> fixedIpMap = Maps.newHashMap(); |
68 | JsonNode portInfo = json.get(PORT); | 67 | JsonNode portInfo = json.get(PORT); |
69 | if (portInfo == null) { | 68 | if (portInfo == null) { |
70 | portInfo = json; | 69 | portInfo = json; | ... | ... |
... | @@ -2,10 +2,42 @@ | ... | @@ -2,10 +2,42 @@ |
2 | "apps" : { | 2 | "apps" : { |
3 | "org.onosproject.openstackrouting" : { | 3 | "org.onosproject.openstackrouting" : { |
4 | "openstackrouting" : { | 4 | "openstackrouting" : { |
5 | - "physicalRouterMac" : "2a:a1:8a:89:dd:a4", | 5 | + "physicalRouterMac" : "36:e3:f7:7b:cc:52", |
6 | "gatewayBridgeId" : "of:0000000000000003", | 6 | "gatewayBridgeId" : "of:0000000000000003", |
7 | "gatewayExternalInterfaceName" : "veth0", | 7 | "gatewayExternalInterfaceName" : "veth0", |
8 | - "gatewayExternalInterfaceMac" : "be:15:c6:b0:df:9f" | 8 | + "gatewayExternalInterfaceMac" : "96:87:bc:64:99:ad", |
9 | + "nodes" : [ | ||
10 | + { | ||
11 | + "dataPlaneIp" : "192.168.57.103", | ||
12 | + "bridgeId" : "of:0000000000000001" | ||
13 | + }, | ||
14 | + { | ||
15 | + "dataPlaneIp" : "192.168.57.104", | ||
16 | + "bridgeId" : "of:0000000000000002" | ||
17 | + }, | ||
18 | + { | ||
19 | + "dataPlaneIp" : "192.168.57.105", | ||
20 | + "bridgeId" : "of:0000000000000003" | ||
21 | + } | ||
22 | + ] | ||
23 | + } | ||
24 | + }, | ||
25 | + "org.onosproject.openstackswitching" : { | ||
26 | + "openstackswitching" : { | ||
27 | + "nodes" : [ | ||
28 | + { | ||
29 | + "dataPlaneIp" : "192.168.57.103", | ||
30 | + "bridgeId" : "of:0000000000000001" | ||
31 | + }, | ||
32 | + { | ||
33 | + "dataPlaneIp" : "192.168.57.104", | ||
34 | + "bridgeId" : "of:0000000000000002" | ||
35 | + }, | ||
36 | + { | ||
37 | + "dataPlaneIp" : "192.168.57.105", | ||
38 | + "bridgeId" : "of:0000000000000003" | ||
39 | + } | ||
40 | + ] | ||
9 | } | 41 | } |
10 | }, | 42 | }, |
11 | "org.onosproject.openstacknode" : { | 43 | "org.onosproject.openstacknode" : { |
... | @@ -13,14 +45,14 @@ | ... | @@ -13,14 +45,14 @@ |
13 | "nodes" : [ | 45 | "nodes" : [ |
14 | { | 46 | { |
15 | "hostname" : "compute-01", | 47 | "hostname" : "compute-01", |
16 | - "ovsdbIp" : "192.168.56.112", | 48 | + "ovsdbIp" : "192.168.56.121", |
17 | "ovsdbPort" : "6640", | 49 | "ovsdbPort" : "6640", |
18 | "bridgeId" : "of:0000000000000001", | 50 | "bridgeId" : "of:0000000000000001", |
19 | "openstackNodeType" : "COMPUTENODE" | 51 | "openstackNodeType" : "COMPUTENODE" |
20 | }, | 52 | }, |
21 | { | 53 | { |
22 | "hostname" : "compute-02", | 54 | "hostname" : "compute-02", |
23 | - "ovsdbIp" : "192.168.56.113", | 55 | + "ovsdbIp" : "192.168.56.122", |
24 | "ovsdbPort" : "6640", | 56 | "ovsdbPort" : "6640", |
25 | "bridgeId" : "of:0000000000000002", | 57 | "bridgeId" : "of:0000000000000002", |
26 | "openstackNodeType" : "COMPUTENODE" | 58 | "openstackNodeType" : "COMPUTENODE" |
... | @@ -32,17 +64,17 @@ | ... | @@ -32,17 +64,17 @@ |
32 | "bridgeId" : "of:0000000000000003", | 64 | "bridgeId" : "of:0000000000000003", |
33 | "openstackNodeType" : "GATEWAYNODE", | 65 | "openstackNodeType" : "GATEWAYNODE", |
34 | "gatewayExternalInterfaceName" : "veth0", | 66 | "gatewayExternalInterfaceName" : "veth0", |
35 | - "gatewayExternalInterfaceMac" : "be:15:c6:b0:df:9f" | 67 | + "gatewayExternalInterfaceMac" : "96:87:bc:64:99:ad" |
36 | } | 68 | } |
37 | ] | 69 | ] |
38 | } | 70 | } |
39 | }, | 71 | }, |
40 | "org.onosproject.openstackinterface" : { | 72 | "org.onosproject.openstackinterface" : { |
41 | "openstackinterface" : { | 73 | "openstackinterface" : { |
42 | - "neutron_server" : "http://192.168.56.111:9696/v2.0/", | 74 | + "neutron_server" : "http://192.168.56.118:9696/v2.0/", |
43 | - "keystone_server" : "http://192.168.56.111:5000/v2.0/", | 75 | + "keystone_server" : "http://192.168.56.118:5000/v2.0/", |
44 | "user_name" : "admin", | 76 | "user_name" : "admin", |
45 | - "password" : "nova" | 77 | + "password" : "rocks" |
46 | } | 78 | } |
47 | } | 79 | } |
48 | }, | 80 | }, | ... | ... |
... | @@ -15,10 +15,16 @@ | ... | @@ -15,10 +15,16 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking.routing; | 16 | package org.onosproject.openstacknetworking.routing; |
17 | 17 | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import com.google.common.collect.Maps; | ||
20 | +import org.onlab.packet.Ip4Address; | ||
18 | import org.onosproject.core.ApplicationId; | 21 | import org.onosproject.core.ApplicationId; |
22 | +import org.onosproject.net.DeviceId; | ||
19 | import org.onosproject.net.config.Config; | 23 | import org.onosproject.net.config.Config; |
20 | import org.slf4j.Logger; | 24 | import org.slf4j.Logger; |
21 | 25 | ||
26 | +import java.util.Map; | ||
27 | + | ||
22 | import static org.slf4j.LoggerFactory.getLogger; | 28 | import static org.slf4j.LoggerFactory.getLogger; |
23 | 29 | ||
24 | /** | 30 | /** |
... | @@ -31,6 +37,35 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { | ... | @@ -31,6 +37,35 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { |
31 | public static final String GATEWAY_BRIDGE_ID = "gatewayBridgeId"; | 37 | public static final String GATEWAY_BRIDGE_ID = "gatewayBridgeId"; |
32 | public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName"; | 38 | public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName"; |
33 | public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac"; | 39 | public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac"; |
40 | + public static final String NODES = "nodes"; | ||
41 | + public static final String DATAPLANE_IP = "dataPlaneIp"; | ||
42 | + public static final String BRIDGE_ID = "bridgeId"; | ||
43 | + | ||
44 | + | ||
45 | + /** | ||
46 | + * Returns the data plane IP map of nodes read from network config. | ||
47 | + * | ||
48 | + * @return data plane IP map | ||
49 | + */ | ||
50 | + public Map<DeviceId, Ip4Address> nodes() { | ||
51 | + Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap(); | ||
52 | + | ||
53 | + JsonNode jsonNodes = object.get(NODES); | ||
54 | + if (jsonNodes == null) { | ||
55 | + log.error("There's no node information"); | ||
56 | + return null; | ||
57 | + } | ||
58 | + | ||
59 | + jsonNodes.forEach(jsonNode -> { | ||
60 | + try { | ||
61 | + nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()), | ||
62 | + Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())); | ||
63 | + } catch (IllegalArgumentException | NullPointerException e) { | ||
64 | + log.error("Failed to read {}", e.toString()); | ||
65 | + } | ||
66 | + }); | ||
67 | + return nodeMap; | ||
68 | + } | ||
34 | 69 | ||
35 | /** | 70 | /** |
36 | * Returns physical router mac. | 71 | * Returns physical router mac. |
... | @@ -38,7 +73,7 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { | ... | @@ -38,7 +73,7 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { |
38 | * @return physical router mac | 73 | * @return physical router mac |
39 | */ | 74 | */ |
40 | public String physicalRouterMac() { | 75 | public String physicalRouterMac() { |
41 | - return this.get("physicalRouterMac", ""); | 76 | + return this.get(PHYSICAL_ROUTER_MAC, ""); |
42 | } | 77 | } |
43 | 78 | ||
44 | /** | 79 | /** |
... | @@ -47,7 +82,7 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { | ... | @@ -47,7 +82,7 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { |
47 | * @return bridge id | 82 | * @return bridge id |
48 | */ | 83 | */ |
49 | public String gatewayBridgeId() { | 84 | public String gatewayBridgeId() { |
50 | - return this.get("gatewayBridgeId", ""); | 85 | + return this.get(GATEWAY_BRIDGE_ID, ""); |
51 | } | 86 | } |
52 | 87 | ||
53 | /** | 88 | /** |
... | @@ -56,7 +91,7 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { | ... | @@ -56,7 +91,7 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { |
56 | * @return external interface name | 91 | * @return external interface name |
57 | */ | 92 | */ |
58 | public String gatewayExternalInterfaceName() { | 93 | public String gatewayExternalInterfaceName() { |
59 | - return this.get("gatewayExternalInterfaceName", ""); | 94 | + return this.get(GATEWAY_EXTERNAL_INTERFACE_NAME, ""); |
60 | } | 95 | } |
61 | 96 | ||
62 | /** | 97 | /** |
... | @@ -65,6 +100,6 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { | ... | @@ -65,6 +100,6 @@ public class OpenstackRoutingConfig extends Config<ApplicationId> { |
65 | * @return external interface mac | 100 | * @return external interface mac |
66 | */ | 101 | */ |
67 | public String gatewayExternalInterfaceMac() { | 102 | public String gatewayExternalInterfaceMac() { |
68 | - return this.get("gatewayExternalInterfaceMac", ""); | 103 | + return this.get(GATEWAY_EXTERNAL_INTERFACE_MAC, ""); |
69 | } | 104 | } |
70 | } | 105 | } | ... | ... |
... | @@ -62,6 +62,8 @@ import org.slf4j.LoggerFactory; | ... | @@ -62,6 +62,8 @@ import org.slf4j.LoggerFactory; |
62 | 62 | ||
63 | import java.util.Collection; | 63 | import java.util.Collection; |
64 | import java.util.List; | 64 | import java.util.List; |
65 | +import java.util.Map; | ||
66 | +import java.util.Optional; | ||
65 | import java.util.concurrent.ExecutorService; | 67 | import java.util.concurrent.ExecutorService; |
66 | import java.util.concurrent.Executors; | 68 | import java.util.concurrent.Executors; |
67 | import java.util.stream.Collectors; | 69 | import java.util.stream.Collectors; |
... | @@ -108,6 +110,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -108,6 +110,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
108 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 110 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
109 | protected StorageService storageService; | 111 | protected StorageService storageService; |
110 | 112 | ||
113 | + | ||
111 | private ApplicationId appId; | 114 | private ApplicationId appId; |
112 | private ConsistentMap<Integer, String> tpPortNumMap; // Map<PortNum, allocated VM`s Mac & destionation Ip address> | 115 | private ConsistentMap<Integer, String> tpPortNumMap; // Map<PortNum, allocated VM`s Mac & destionation Ip address> |
113 | private ConsistentMap<String, OpenstackFloatingIP> floatingIpMap; // Map<FloatingIp`s Id, FloatingIp object> | 116 | private ConsistentMap<String, OpenstackFloatingIP> floatingIpMap; // Map<FloatingIp`s Id, FloatingIp object> |
... | @@ -117,6 +120,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -117,6 +120,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
117 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; | 120 | private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface"; |
118 | private static final String FLOATING_IP_MAP_NAME = "openstackrouting-floatingip"; | 121 | private static final String FLOATING_IP_MAP_NAME = "openstackrouting-floatingip"; |
119 | private static final String TP_PORT_MAP_NAME = "openstackrouting-portnum"; | 122 | private static final String TP_PORT_MAP_NAME = "openstackrouting-portnum"; |
123 | + private static final String COLON = ":"; | ||
120 | private static final int PNAT_PORT_EXPIRE_TIME = 1200 * 1000; | 124 | private static final int PNAT_PORT_EXPIRE_TIME = 1200 * 1000; |
121 | private static final int TP_PORT_MINIMUM_NUM = 1024; | 125 | private static final int TP_PORT_MINIMUM_NUM = 1024; |
122 | private static final int TP_PORT_MAXIMUM_NUM = 65535; | 126 | private static final int TP_PORT_MAXIMUM_NUM = 65535; |
... | @@ -154,6 +158,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -154,6 +158,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
154 | private OpenstackIcmpHandler openstackIcmpHandler; | 158 | private OpenstackIcmpHandler openstackIcmpHandler; |
155 | private OpenstackRoutingArpHandler openstackArpHandler; | 159 | private OpenstackRoutingArpHandler openstackArpHandler; |
156 | private OpenstackRoutingRulePopulator rulePopulator; | 160 | private OpenstackRoutingRulePopulator rulePopulator; |
161 | + private Map<DeviceId, Ip4Address> computeNodeMap; | ||
157 | 162 | ||
158 | @Activate | 163 | @Activate |
159 | protected void activate() { | 164 | protected void activate() { |
... | @@ -314,7 +319,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -314,7 +319,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
314 | } | 319 | } |
315 | 320 | ||
316 | private void reloadInitL3Rules() { | 321 | private void reloadInitL3Rules() { |
317 | - l3EventExecutorService.submit(() -> | 322 | + l3EventExecutorService.execute(() -> |
318 | openstackService.ports() | 323 | openstackService.ports() |
319 | .stream() | 324 | .stream() |
320 | .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)) | 325 | .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)) |
... | @@ -359,7 +364,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -359,7 +364,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
359 | switch (iPacket.getProtocol()) { | 364 | switch (iPacket.getProtocol()) { |
360 | case IPv4.PROTOCOL_ICMP: | 365 | case IPv4.PROTOCOL_ICMP: |
361 | 366 | ||
362 | - icmpEventExecutorService.submit(() -> | 367 | + icmpEventExecutorService.execute(() -> |
363 | openstackIcmpHandler.processIcmpPacket(context, ethernet)); | 368 | openstackIcmpHandler.processIcmpPacket(context, ethernet)); |
364 | break; | 369 | break; |
365 | case IPv4.PROTOCOL_UDP: | 370 | case IPv4.PROTOCOL_UDP: |
... | @@ -371,20 +376,21 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -371,20 +376,21 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
371 | } | 376 | } |
372 | default: | 377 | default: |
373 | int portNum = getPortNum(ethernet.getSourceMAC(), iPacket.getDestinationAddress()); | 378 | int portNum = getPortNum(ethernet.getSourceMAC(), iPacket.getDestinationAddress()); |
374 | - Port port = | 379 | + Optional<Port> port = |
375 | getExternalPort(pkt.receivedFrom().deviceId(), config.gatewayExternalInterfaceName()); | 380 | getExternalPort(pkt.receivedFrom().deviceId(), config.gatewayExternalInterfaceName()); |
376 | - if (port == null) { | 381 | + |
382 | + if (!port.isPresent()) { | ||
377 | log.warn("There`s no external interface"); | 383 | log.warn("There`s no external interface"); |
378 | - break; | 384 | + } else { |
379 | - } | ||
380 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), | 385 | OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), |
381 | Ip4Address.valueOf(iPacket.getSourceAddress())); | 386 | Ip4Address.valueOf(iPacket.getSourceAddress())); |
382 | l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, | 387 | l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, |
383 | - portNum, openstackPort, port, config)); | 388 | + portNum, openstackPort, port.get(), config)); |
389 | + } | ||
384 | break; | 390 | break; |
385 | } | 391 | } |
386 | } else if (ethernet.getEtherType() == Ethernet.TYPE_ARP) { | 392 | } else if (ethernet.getEtherType() == Ethernet.TYPE_ARP) { |
387 | - arpEventExecutorService.submit(() -> | 393 | + arpEventExecutorService.execute(() -> |
388 | openstackArpHandler.processArpPacketFromRouter(context, ethernet)); | 394 | openstackArpHandler.processArpPacketFromRouter(context, ethernet)); |
389 | } | 395 | } |
390 | } | 396 | } |
... | @@ -395,7 +401,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -395,7 +401,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
395 | clearPortNumMap(); | 401 | clearPortNumMap(); |
396 | portNum = findUnusedPortNum(); | 402 | portNum = findUnusedPortNum(); |
397 | } | 403 | } |
398 | - tpPortNumMap.put(portNum, sourceMac.toString().concat(":").concat(String.valueOf(destinationAddress))); | 404 | + tpPortNumMap.put(portNum, sourceMac.toString().concat(COLON).concat(String.valueOf(destinationAddress))); |
399 | return portNum; | 405 | return portNum; |
400 | } | 406 | } |
401 | 407 | ||
... | @@ -418,12 +424,11 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -418,12 +424,11 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
418 | }); | 424 | }); |
419 | } | 425 | } |
420 | 426 | ||
421 | - private Port getExternalPort(DeviceId deviceId, String interfaceName) { | 427 | + private Optional<Port> getExternalPort(DeviceId deviceId, String interfaceName) { |
422 | return deviceService.getPorts(deviceId) | 428 | return deviceService.getPorts(deviceId) |
423 | .stream() | 429 | .stream() |
424 | .filter(p -> p.annotations().value(PORT_NAME).equals(interfaceName)) | 430 | .filter(p -> p.annotations().value(PORT_NAME).equals(interfaceName)) |
425 | - .findAny() | 431 | + .findAny(); |
426 | - .orElse(null); | ||
427 | } | 432 | } |
428 | 433 | ||
429 | private void checkExternalConnection(OpenstackRouter router, | 434 | private void checkExternalConnection(OpenstackRouter router, |
... | @@ -436,33 +441,26 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -436,33 +441,26 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
436 | log.debug("Not satisfied to set pnat configuration"); | 441 | log.debug("Not satisfied to set pnat configuration"); |
437 | return; | 442 | return; |
438 | } | 443 | } |
439 | - if (router.id() == null) { | 444 | + interfaces.forEach(this::initiateL3Rule); |
440 | - interfaces.forEach(i -> initiateL3Rule(getRouterfromExternalIp(externalIp), i)); | ||
441 | - } else { | ||
442 | - interfaces.forEach(i -> initiateL3Rule(router, i)); | ||
443 | - } | ||
444 | - | ||
445 | } | 445 | } |
446 | 446 | ||
447 | - private OpenstackRouter getRouterfromExternalIp(Ip4Address externalIp) { | 447 | + private Optional<OpenstackRouter> getRouterfromExternalIp(Ip4Address externalIp) { |
448 | - OpenstackRouter router = getExternalRouter(true) | 448 | + return getExternalRouter(true) |
449 | .stream() | 449 | .stream() |
450 | .filter(r -> r.gatewayExternalInfo() | 450 | .filter(r -> r.gatewayExternalInfo() |
451 | .externalFixedIps() | 451 | .externalFixedIps() |
452 | .values() | 452 | .values() |
453 | .stream() | 453 | .stream() |
454 | - .findFirst() | ||
455 | - .orElse(null) | ||
456 | - .equals(externalIp)) | ||
457 | .findAny() | 454 | .findAny() |
458 | - .orElse(null); | 455 | + .get() |
459 | - return checkNotNull(router); | 456 | + .equals(externalIp)) |
457 | + .findAny(); | ||
460 | } | 458 | } |
461 | 459 | ||
462 | - private void initiateL3Rule(OpenstackRouter router, OpenstackRouterInterface routerInterface) { | 460 | + private void initiateL3Rule(OpenstackRouterInterface routerInterface) { |
463 | long vni = Long.parseLong(openstackService.network(openstackService | 461 | long vni = Long.parseLong(openstackService.network(openstackService |
464 | .port(routerInterface.portId()).networkId()).segmentId()); | 462 | .port(routerInterface.portId()).networkId()).segmentId()); |
465 | - rulePopulator.populateExternalRules(vni, router, routerInterface); | 463 | + rulePopulator.populateExternalRules(vni); |
466 | } | 464 | } |
467 | 465 | ||
468 | private Collection<OpenstackRouterInterface> getOpenstackRouterInterface(OpenstackRouter router) { | 466 | private Collection<OpenstackRouterInterface> getOpenstackRouterInterface(OpenstackRouter router) { |
... | @@ -472,8 +470,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -472,8 +470,7 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
472 | .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)) | 470 | .filter(p -> p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)) |
473 | .filter(p -> p.deviceId().equals(router.id())) | 471 | .filter(p -> p.deviceId().equals(router.id())) |
474 | .forEach(p -> { | 472 | .forEach(p -> { |
475 | - OpenstackRouterInterface routerInterface = portToRouterInterface(p); | 473 | + interfaces.add(portToRouterInterface(p)); |
476 | - interfaces.add(routerInterface); | ||
477 | }); | 474 | }); |
478 | return interfaces; | 475 | return interfaces; |
479 | } | 476 | } |
... | @@ -529,9 +526,6 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { | ... | @@ -529,9 +526,6 @@ public class OpenstackRoutingManager implements OpenstackRoutingService { |
529 | if (event.type().equals(NetworkConfigEvent.Type.CONFIG_ADDED) || | 526 | if (event.type().equals(NetworkConfigEvent.Type.CONFIG_ADDED) || |
530 | event.type().equals(NetworkConfigEvent.Type.CONFIG_UPDATED)) { | 527 | event.type().equals(NetworkConfigEvent.Type.CONFIG_UPDATED)) { |
531 | l3EventExecutorService.execute(OpenstackRoutingManager.this::readConfiguration); | 528 | l3EventExecutorService.execute(OpenstackRoutingManager.this::readConfiguration); |
532 | - rulePopulator = new OpenstackRoutingRulePopulator(appId, | ||
533 | - openstackService, flowObjectiveService, deviceService, driverService, config); | ||
534 | - | ||
535 | } | 529 | } |
536 | } | 530 | } |
537 | } | 531 | } | ... | ... |
... | @@ -49,7 +49,6 @@ import org.onosproject.net.flowobjective.ForwardingObjective; | ... | @@ -49,7 +49,6 @@ import org.onosproject.net.flowobjective.ForwardingObjective; |
49 | import org.onosproject.net.packet.InboundPacket; | 49 | import org.onosproject.net.packet.InboundPacket; |
50 | import org.onosproject.openstackinterface.OpenstackInterfaceService; | 50 | import org.onosproject.openstackinterface.OpenstackInterfaceService; |
51 | import org.onosproject.openstackinterface.OpenstackPort; | 51 | import org.onosproject.openstackinterface.OpenstackPort; |
52 | -import org.onosproject.openstackinterface.OpenstackRouter; | ||
53 | import org.onosproject.openstackinterface.OpenstackRouterInterface; | 52 | import org.onosproject.openstackinterface.OpenstackRouterInterface; |
54 | import org.onosproject.openstackinterface.OpenstackSubnet; | 53 | import org.onosproject.openstackinterface.OpenstackSubnet; |
55 | import org.onosproject.openstackinterface.OpenstackFloatingIP; | 54 | import org.onosproject.openstackinterface.OpenstackFloatingIP; |
... | @@ -82,11 +81,11 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -82,11 +81,11 @@ public class OpenstackRoutingRulePopulator { |
82 | private static final String PORTNOTNULL = "Port can not be null"; | 81 | private static final String PORTNOTNULL = "Port can not be null"; |
83 | private static final String DEVICENOTNULL = "Device can not be null"; | 82 | private static final String DEVICENOTNULL = "Device can not be null"; |
84 | private static final String TUNNEL_DESTINATION = "tunnelDst"; | 83 | private static final String TUNNEL_DESTINATION = "tunnelDst"; |
85 | - private static final String DEVICE_ANNOTATION_CHANNELID = "channelId"; | ||
86 | private static final int ROUTING_RULE_PRIORITY = 25000; | 84 | private static final int ROUTING_RULE_PRIORITY = 25000; |
87 | private static final int FLOATING_RULE_PRIORITY = 42000; | 85 | private static final int FLOATING_RULE_PRIORITY = 42000; |
88 | private static final int PNAT_RULE_PRIORITY = 26000; | 86 | private static final int PNAT_RULE_PRIORITY = 26000; |
89 | private static final int PNAT_TIMEOUT = 120; | 87 | private static final int PNAT_TIMEOUT = 120; |
88 | + private static final int PREFIX_LENGTH = 32; | ||
90 | private static final MacAddress GATEWAYMAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | 89 | private static final MacAddress GATEWAYMAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); |
91 | 90 | ||
92 | private InboundPacket inboundPacket; | 91 | private InboundPacket inboundPacket; |
... | @@ -94,8 +93,6 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -94,8 +93,6 @@ public class OpenstackRoutingRulePopulator { |
94 | private int portNum; | 93 | private int portNum; |
95 | private MacAddress externalInterface; | 94 | private MacAddress externalInterface; |
96 | private MacAddress externalRouter; | 95 | private MacAddress externalRouter; |
97 | - private OpenstackRouter router; | ||
98 | - private OpenstackRouterInterface routerInterface; | ||
99 | 96 | ||
100 | /** | 97 | /** |
101 | * The constructor of openstackRoutingRulePopulator. | 98 | * The constructor of openstackRoutingRulePopulator. |
... | @@ -247,7 +244,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -247,7 +244,7 @@ public class OpenstackRoutingRulePopulator { |
247 | 244 | ||
248 | private Ip4Address getHostIpfromOpenstackPort(OpenstackPort openstackPort) { | 245 | private Ip4Address getHostIpfromOpenstackPort(OpenstackPort openstackPort) { |
249 | Device device = getDevicefromOpenstackPort(openstackPort); | 246 | Device device = getDevicefromOpenstackPort(openstackPort); |
250 | - return getIPAddressforDevice(device); | 247 | + return config.nodes().get(device.id()); |
251 | } | 248 | } |
252 | 249 | ||
253 | private Device getDevicefromOpenstackPort(OpenstackPort openstackPort) { | 250 | private Device getDevicefromOpenstackPort(OpenstackPort openstackPort) { |
... | @@ -266,7 +263,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -266,7 +263,7 @@ public class OpenstackRoutingRulePopulator { |
266 | .filter(p -> p.isEnabled() && p.annotations().value(PORTNAME).equals(openstackPortName)) | 263 | .filter(p -> p.isEnabled() && p.annotations().value(PORTNAME).equals(openstackPortName)) |
267 | .findAny() | 264 | .findAny() |
268 | .orElse(null); | 265 | .orElse(null); |
269 | - return port != null ? true : false; | 266 | + return port != null; |
270 | } | 267 | } |
271 | 268 | ||
272 | /** | 269 | /** |
... | @@ -317,13 +314,8 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -317,13 +314,8 @@ public class OpenstackRoutingRulePopulator { |
317 | * Populates flow rules from openstackComputeNode to GatewayNode. | 314 | * Populates flow rules from openstackComputeNode to GatewayNode. |
318 | * | 315 | * |
319 | * @param vni Target network | 316 | * @param vni Target network |
320 | - * @param router corresponding router | ||
321 | - * @param routerInterface corresponding routerInterface | ||
322 | */ | 317 | */ |
323 | - public void populateExternalRules(long vni, OpenstackRouter router, | 318 | + public void populateExternalRules(long vni) { |
324 | - OpenstackRouterInterface routerInterface) { | ||
325 | - this.router = router; | ||
326 | - this.routerInterface = routerInterface; | ||
327 | 319 | ||
328 | // 1. computeNode to gateway | 320 | // 1. computeNode to gateway |
329 | populateComputeNodeRules(vni); | 321 | populateComputeNodeRules(vni); |
... | @@ -367,7 +359,7 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -367,7 +359,7 @@ public class OpenstackRoutingRulePopulator { |
367 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 359 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
368 | .matchTunnelId(vni) | 360 | .matchTunnelId(vni) |
369 | .matchEthDst(GATEWAYMAC); | 361 | .matchEthDst(GATEWAYMAC); |
370 | - tBuilder.extension(buildNiciraExtenstion(d.id(), getIPAddressforDevice(gatewayDevice)), d.id()) | 362 | + tBuilder.extension(buildNiciraExtenstion(d.id(), config.nodes().get(gatewayDevice.id())), d.id()) |
371 | .setOutput(getTunnelPort(d.id())); | 363 | .setOutput(getTunnelPort(d.id())); |
372 | 364 | ||
373 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 365 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -381,10 +373,6 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -381,10 +373,6 @@ public class OpenstackRoutingRulePopulator { |
381 | flowObjectiveService.forward(d.id(), fo); | 373 | flowObjectiveService.forward(d.id(), fo); |
382 | } | 374 | } |
383 | 375 | ||
384 | - private Ip4Address getIPAddressforDevice(Device device) { | ||
385 | - return Ip4Address.valueOf(device.annotations().value(DEVICE_ANNOTATION_CHANNELID).split(":")[0]); | ||
386 | - } | ||
387 | - | ||
388 | private Device getGatewayNode() { | 376 | private Device getGatewayNode() { |
389 | return checkNotNull(deviceService.getDevice(DeviceId.deviceId(config.gatewayBridgeId()))); | 377 | return checkNotNull(deviceService.getDevice(DeviceId.deviceId(config.gatewayBridgeId()))); |
390 | } | 378 | } |
... | @@ -411,11 +399,10 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -411,11 +399,10 @@ public class OpenstackRoutingRulePopulator { |
411 | 399 | ||
412 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) | 400 | StreamSupport.stream(deviceService.getDevices().spliterator(), false) |
413 | .forEach(d -> { | 401 | .forEach(d -> { |
414 | - if (checkGatewayNode(d.id())) { | 402 | + ForwardingObjective.Flag flag = checkGatewayNode(d.id()) ? |
415 | - removeRule(d.id(), sBuilder, ForwardingObjective.Flag.VERSATILE, ROUTING_RULE_PRIORITY); | 403 | + ForwardingObjective.Flag.VERSATILE : ForwardingObjective.Flag.SPECIFIC; |
416 | - } else { | 404 | + |
417 | - removeRule(d.id(), sBuilder, ForwardingObjective.Flag.SPECIFIC, ROUTING_RULE_PRIORITY); | 405 | + removeRule(d.id(), sBuilder, flag, ROUTING_RULE_PRIORITY); |
418 | - } | ||
419 | }); | 406 | }); |
420 | 407 | ||
421 | } | 408 | } |
... | @@ -457,13 +444,14 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -457,13 +444,14 @@ public class OpenstackRoutingRulePopulator { |
457 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); | 444 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
458 | 445 | ||
459 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) | 446 | sBuilder.matchEthType(Ethernet.TYPE_IPV4) |
460 | - .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), 32)); | 447 | + .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); |
461 | 448 | ||
462 | tBuilder.setEthSrc(MacAddress.valueOf(config.gatewayExternalInterfaceMac())) | 449 | tBuilder.setEthSrc(MacAddress.valueOf(config.gatewayExternalInterfaceMac())) |
463 | .setEthDst(port.macAddress()) | 450 | .setEthDst(port.macAddress()) |
464 | .setIpDst(floatingIP.fixedIpAddress()) | 451 | .setIpDst(floatingIP.fixedIpAddress()) |
465 | .setTunnelId(getVni(port.networkId())) | 452 | .setTunnelId(getVni(port.networkId())) |
466 | - .extension(buildNiciraExtenstion(gatewayNode.id(), getIPAddressforDevice(portNode)), gatewayNode.id()) | 453 | + .extension(buildNiciraExtenstion(gatewayNode.id(), |
454 | + config.nodes().get(portNode.id())), gatewayNode.id()) | ||
467 | .setOutput(getTunnelPort(gatewayNode.id())); | 455 | .setOutput(getTunnelPort(gatewayNode.id())); |
468 | 456 | ||
469 | ForwardingObjective fo = DefaultForwardingObjective.builder() | 457 | ForwardingObjective fo = DefaultForwardingObjective.builder() |
... | @@ -516,10 +504,10 @@ public class OpenstackRoutingRulePopulator { | ... | @@ -516,10 +504,10 @@ public class OpenstackRoutingRulePopulator { |
516 | 504 | ||
517 | sOutgoingBuilder.matchEthType(Ethernet.TYPE_IPV4) | 505 | sOutgoingBuilder.matchEthType(Ethernet.TYPE_IPV4) |
518 | .matchTunnelId(portInfo.vni()) | 506 | .matchTunnelId(portInfo.vni()) |
519 | - .matchIPSrc(IpPrefix.valueOf(portInfo.ip(), 32)); | 507 | + .matchIPSrc(IpPrefix.valueOf(portInfo.ip(), PREFIX_LENGTH)); |
520 | 508 | ||
521 | sIncomingBuilder.matchEthType(Ethernet.TYPE_IPV4) | 509 | sIncomingBuilder.matchEthType(Ethernet.TYPE_IPV4) |
522 | - .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), 32)); | 510 | + .matchIPDst(IpPrefix.valueOf(floatingIP.floatingIpAddress(), PREFIX_LENGTH)); |
523 | 511 | ||
524 | removeRule(getGatewayNode().id(), sOutgoingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); | 512 | removeRule(getGatewayNode().id(), sOutgoingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); |
525 | removeRule(getGatewayNode().id(), sIncomingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); | 513 | removeRule(getGatewayNode().id(), sIncomingBuilder, ForwardingObjective.Flag.VERSATILE, FLOATING_RULE_PRIORITY); | ... | ... |
1 | -{ | ||
2 | - "apps" : { | ||
3 | - "org.onosproject.openstackswitching" : { | ||
4 | - "openstackswitching" : { | ||
5 | - "do_not_push_flows" : "false", | ||
6 | - "neutron_server" : "http://10.40.101.209:9696/v2.0/", | ||
7 | - "keystone_server" : "http://10.40.101.209:5000/v2.0/", | ||
8 | - "user_name" : "admin", | ||
9 | - "password" : "nova" | ||
10 | - } | ||
11 | - }, | ||
12 | - "org.onosproject.dhcp" : { | ||
13 | - "dhcp" : { | ||
14 | - "ip": "10.0.0.1", | ||
15 | - "mac": "1a:2b:3c:4e:5e:6f", | ||
16 | - "subnet": "255.0.0.0", | ||
17 | - "broadcast": "10.255.255.255", | ||
18 | - "router": "10.0.0.1", | ||
19 | - "domain": "10.0.0.1", | ||
20 | - "ttl": "63", | ||
21 | - "lease": "300", | ||
22 | - "renew": "150", | ||
23 | - "rebind": "200", | ||
24 | - "delay": "3", | ||
25 | - "timeout": "150", | ||
26 | - "startip": "10.0.0.110", | ||
27 | - "endip": "10.0.0.130" | ||
28 | - } | ||
29 | - }, | ||
30 | - "org.onosproject.cordvtn" : { | ||
31 | - "cordvtn" : { | ||
32 | - "nodes" : [ | ||
33 | - { | ||
34 | - "hostname" : "compute-01", | ||
35 | - "ovsdbIp" : "10.40.101.208", | ||
36 | - "ovsdbPort" : "6640", | ||
37 | - "bridgeId" : "of:0000000000000001" | ||
38 | - }, | ||
39 | - { | ||
40 | - "hostname" : "compute-02", | ||
41 | - "ovsdbIp" : "10.40.101.227", | ||
42 | - "ovsdbPort" : "6640", | ||
43 | - "bridgeId" : "of:0000000000000002" | ||
44 | - }, | ||
45 | - { | ||
46 | - "hostname" : "network", | ||
47 | - "ovsdbIp" : "10.40.101.209", | ||
48 | - "ovsdbPort" : "6640", | ||
49 | - "bridgeId" : "of:0000000000000003" | ||
50 | - } | ||
51 | - ] | ||
52 | - } | ||
53 | - } | ||
54 | - }, | ||
55 | - "devices" : { | ||
56 | - "of:0000000000000001" : { | ||
57 | - "basic" : { | ||
58 | - "driver" : "sona" | ||
59 | - } | ||
60 | - }, | ||
61 | - "of:0000000000000002" : { | ||
62 | - "basic" : { | ||
63 | - "driver" : "sona" | ||
64 | - } | ||
65 | - }, | ||
66 | - "of:0000000000000003" : { | ||
67 | - "basic" : { | ||
68 | - "driver" : "sona" | ||
69 | - } | ||
70 | - } | ||
71 | - } | ||
72 | -} |
1 | +/* | ||
2 | + * Copyright 2016 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.switching; | ||
17 | + | ||
18 | +import com.fasterxml.jackson.databind.JsonNode; | ||
19 | +import com.google.common.collect.Maps; | ||
20 | +import org.onlab.packet.Ip4Address; | ||
21 | +import org.onosproject.core.ApplicationId; | ||
22 | +import org.onosproject.net.DeviceId; | ||
23 | +import org.onosproject.net.config.Config; | ||
24 | +import org.slf4j.Logger; | ||
25 | + | ||
26 | +import java.util.Map; | ||
27 | + | ||
28 | +import static org.slf4j.LoggerFactory.getLogger; | ||
29 | + | ||
30 | +/** | ||
31 | + * Configuration object for OpenstackSwitching service. | ||
32 | + */ | ||
33 | +public class OpenstackSwitchingConfig extends Config<ApplicationId> { | ||
34 | + | ||
35 | + protected final Logger log = getLogger(getClass()); | ||
36 | + | ||
37 | + public static final String NODES = "nodes"; | ||
38 | + public static final String DATAPLANE_IP = "dataPlaneIp"; | ||
39 | + public static final String BRIDGE_ID = "bridgeId"; | ||
40 | + | ||
41 | + /** | ||
42 | + * Returns the data plane IP map of nodes read from network config. | ||
43 | + * | ||
44 | + * @return data plane IP map | ||
45 | + */ | ||
46 | + public Map<DeviceId, Ip4Address> nodes() { | ||
47 | + Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap(); | ||
48 | + | ||
49 | + JsonNode jsonNodes = object.get(NODES); | ||
50 | + if (jsonNodes == null) { | ||
51 | + log.error("There's no node information"); | ||
52 | + return null; | ||
53 | + } | ||
54 | + | ||
55 | + jsonNodes.forEach(jsonNode -> { | ||
56 | + try { | ||
57 | + nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()), | ||
58 | + Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText())); | ||
59 | + } catch (IllegalArgumentException | NullPointerException e) { | ||
60 | + log.error("Failed to read {}", e.getMessage()); | ||
61 | + } | ||
62 | + }); | ||
63 | + return nodeMap; | ||
64 | + } | ||
65 | +} |
... | @@ -15,8 +15,8 @@ | ... | @@ -15,8 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking.switching; | 16 | package org.onosproject.openstacknetworking.switching; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableList; | ||
18 | import com.google.common.collect.ImmutableMap; | 19 | import com.google.common.collect.ImmutableMap; |
19 | -import com.google.common.collect.Lists; | ||
20 | import com.google.common.collect.Maps; | 20 | import com.google.common.collect.Maps; |
21 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
... | @@ -32,8 +32,13 @@ import org.onosproject.dhcp.DhcpService; | ... | @@ -32,8 +32,13 @@ import org.onosproject.dhcp.DhcpService; |
32 | import org.onosproject.event.AbstractEvent; | 32 | import org.onosproject.event.AbstractEvent; |
33 | import org.onosproject.net.Device; | 33 | import org.onosproject.net.Device; |
34 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
35 | -import org.onosproject.net.Host; | ||
36 | import org.onosproject.net.Port; | 35 | import org.onosproject.net.Port; |
36 | +import org.onosproject.net.config.ConfigFactory; | ||
37 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
38 | +import org.onosproject.net.config.NetworkConfigListener; | ||
39 | +import org.onosproject.net.config.NetworkConfigRegistry; | ||
40 | +import org.onosproject.net.config.NetworkConfigService; | ||
41 | +import org.onosproject.net.config.basics.SubjectFactories; | ||
37 | import org.onosproject.net.device.DeviceEvent; | 42 | import org.onosproject.net.device.DeviceEvent; |
38 | import org.onosproject.net.device.DeviceListener; | 43 | import org.onosproject.net.device.DeviceListener; |
39 | import org.onosproject.net.device.DeviceService; | 44 | import org.onosproject.net.device.DeviceService; |
... | @@ -70,8 +75,7 @@ import static org.onlab.util.Tools.groupedThreads; | ... | @@ -70,8 +75,7 @@ import static org.onlab.util.Tools.groupedThreads; |
70 | */ | 75 | */ |
71 | public class OpenstackSwitchingManager implements OpenstackSwitchingService { | 76 | public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
72 | 77 | ||
73 | - private final Logger log = LoggerFactory | 78 | + private final Logger log = LoggerFactory.getLogger(getClass()); |
74 | - .getLogger(getClass()); | ||
75 | 79 | ||
76 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
77 | protected CoreService coreService; | 81 | protected CoreService coreService; |
... | @@ -97,28 +101,52 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -97,28 +101,52 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 101 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
98 | protected OpenstackInterfaceService openstackService; | 102 | protected OpenstackInterfaceService openstackService; |
99 | 103 | ||
104 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
105 | + protected NetworkConfigService configService; | ||
106 | + | ||
107 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
108 | + protected NetworkConfigRegistry configRegistry; | ||
109 | + | ||
100 | public static final String PORTNAME_PREFIX_VM = "tap"; | 110 | public static final String PORTNAME_PREFIX_VM = "tap"; |
101 | public static final String PORTNAME_PREFIX_ROUTER = "qr-"; | 111 | public static final String PORTNAME_PREFIX_ROUTER = "qr-"; |
102 | public static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; | 112 | public static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; |
103 | public static final String PORTNAME = "portName"; | 113 | public static final String PORTNAME = "portName"; |
104 | private static final String ROUTER_INTERFACE = "network:router_interface"; | 114 | private static final String ROUTER_INTERFACE = "network:router_interface"; |
105 | public static final String DEVICE_OWNER_GATEWAY = "network:router_gateway"; | 115 | public static final String DEVICE_OWNER_GATEWAY = "network:router_gateway"; |
116 | + public static final String DNS_SERVER_IP = "8.8.8.8"; | ||
117 | + private static final String FORWARD_SLASH = "/"; | ||
118 | + | ||
106 | 119 | ||
107 | private ApplicationId appId; | 120 | private ApplicationId appId; |
108 | 121 | ||
109 | private OpenstackArpHandler arpHandler; | 122 | private OpenstackArpHandler arpHandler; |
110 | private OpenstackSecurityGroupRulePopulator sgRulePopulator; | 123 | private OpenstackSecurityGroupRulePopulator sgRulePopulator; |
111 | 124 | ||
112 | - private ExecutorService deviceEventExcutorService = | 125 | + private ExecutorService deviceEventExecutorService = |
113 | Executors.newSingleThreadExecutor(groupedThreads("onos/openstackswitching", "device-event")); | 126 | Executors.newSingleThreadExecutor(groupedThreads("onos/openstackswitching", "device-event")); |
114 | 127 | ||
128 | + private ExecutorService configEventExecutorService = | ||
129 | + Executors.newSingleThreadExecutor(groupedThreads("onos/openstackswitching", "config-event")); | ||
130 | + | ||
115 | private InternalPacketProcessor internalPacketProcessor = new InternalPacketProcessor(); | 131 | private InternalPacketProcessor internalPacketProcessor = new InternalPacketProcessor(); |
116 | private InternalDeviceListener internalDeviceListener = new InternalDeviceListener(); | 132 | private InternalDeviceListener internalDeviceListener = new InternalDeviceListener(); |
117 | private InternalHostListener internalHostListener = new InternalHostListener(); | 133 | private InternalHostListener internalHostListener = new InternalHostListener(); |
118 | 134 | ||
119 | - private Map<String, OpenstackPortInfo> openstackPortInfoMap = Maps.newHashMap(); | 135 | + private final Map<String, OpenstackPortInfo> openstackPortInfoMap = Maps.newHashMap(); |
120 | private Map<String, OpenstackSecurityGroup> securityGroupMap = Maps.newConcurrentMap(); | 136 | private Map<String, OpenstackSecurityGroup> securityGroupMap = Maps.newConcurrentMap(); |
121 | 137 | ||
138 | + private final ConfigFactory configFactory = | ||
139 | + new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, | ||
140 | + OpenstackSwitchingConfig.class, "openstackswitching") { | ||
141 | + @Override | ||
142 | + public OpenstackSwitchingConfig createConfig() { | ||
143 | + return new OpenstackSwitchingConfig(); | ||
144 | + } | ||
145 | + }; | ||
146 | + private final NetworkConfigListener configListener = new InternalConfigListener(); | ||
147 | + | ||
148 | + private OpenstackSwitchingConfig config; | ||
149 | + | ||
122 | @Activate | 150 | @Activate |
123 | protected void activate() { | 151 | protected void activate() { |
124 | appId = coreService | 152 | appId = coreService |
... | @@ -127,12 +155,10 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -127,12 +155,10 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
127 | packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1)); | 155 | packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1)); |
128 | deviceService.addListener(internalDeviceListener); | 156 | deviceService.addListener(internalDeviceListener); |
129 | hostService.addListener(internalHostListener); | 157 | hostService.addListener(internalHostListener); |
130 | - arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService); | 158 | + configRegistry.registerConfigFactory(configFactory); |
159 | + configService.addListener(configListener); | ||
131 | 160 | ||
132 | - arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService); | 161 | + readConfiguration(); |
133 | - sgRulePopulator = new OpenstackSecurityGroupRulePopulator(appId, openstackService, flowObjectiveService); | ||
134 | - | ||
135 | - initializeFlowRules(); | ||
136 | 162 | ||
137 | log.info("Started"); | 163 | log.info("Started"); |
138 | } | 164 | } |
... | @@ -142,7 +168,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -142,7 +168,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
142 | packetService.removeProcessor(internalPacketProcessor); | 168 | packetService.removeProcessor(internalPacketProcessor); |
143 | deviceService.removeListener(internalDeviceListener); | 169 | deviceService.removeListener(internalDeviceListener); |
144 | 170 | ||
145 | - deviceEventExcutorService.shutdown(); | 171 | + deviceEventExecutorService.shutdown(); |
172 | + configEventExecutorService.shutdown(); | ||
173 | + hostService.removeListener(internalHostListener); | ||
174 | + configService.removeListener(configListener); | ||
175 | + configRegistry.unregisterConfigFactory(configFactory); | ||
146 | 176 | ||
147 | log.info("Stopped"); | 177 | log.info("Stopped"); |
148 | } | 178 | } |
... | @@ -151,12 +181,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -151,12 +181,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
151 | public void createPorts(OpenstackPort openstackPort) { | 181 | public void createPorts(OpenstackPort openstackPort) { |
152 | 182 | ||
153 | if (!openstackPort.deviceOwner().equals(ROUTER_INTERFACE) | 183 | if (!openstackPort.deviceOwner().equals(ROUTER_INTERFACE) |
154 | - && !openstackPort.deviceOwner().equals(DEVICE_OWNER_GATEWAY)) { | 184 | + && !openstackPort.deviceOwner().equals(DEVICE_OWNER_GATEWAY) |
155 | - if (!openstackPort.fixedIps().isEmpty()) { | 185 | + && !openstackPort.fixedIps().isEmpty()) { |
156 | registerDhcpInfo(openstackPort); | 186 | registerDhcpInfo(openstackPort); |
157 | } | 187 | } |
158 | } | 188 | } |
159 | - } | ||
160 | 189 | ||
161 | @Override | 190 | @Override |
162 | public void removePort(String uuid) { | 191 | public void removePort(String uuid) { |
... | @@ -170,11 +199,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -170,11 +199,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
170 | if (routerPortInfo != null) { | 199 | if (routerPortInfo != null) { |
171 | dhcpService.removeStaticMapping(routerPortInfo.mac()); | 200 | dhcpService.removeStaticMapping(routerPortInfo.mac()); |
172 | deviceService.getPorts(routerPortInfo.deviceId()).forEach(port -> { | 201 | deviceService.getPorts(routerPortInfo.deviceId()).forEach(port -> { |
173 | - String pName = port.annotations().value("portName"); | 202 | + String pName = port.annotations().value(PORTNAME); |
174 | if (pName.equals(routerPortName)) { | 203 | if (pName.equals(routerPortName)) { |
175 | OpenstackSwitchingRulePopulator rulePopulator = | 204 | OpenstackSwitchingRulePopulator rulePopulator = |
176 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, | 205 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, |
177 | - deviceService, openstackService, driverService); | 206 | + deviceService, openstackService, driverService, config); |
178 | 207 | ||
179 | rulePopulator.removeSwitchingRules(port, openstackPortInfoMap); | 208 | rulePopulator.removeSwitchingRules(port, openstackPortInfoMap); |
180 | openstackPortInfoMap.remove(routerPortName); | 209 | openstackPortInfoMap.remove(routerPortName); |
... | @@ -219,10 +248,6 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -219,10 +248,6 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
219 | return ImmutableMap.copyOf(this.openstackPortInfoMap); | 248 | return ImmutableMap.copyOf(this.openstackPortInfoMap); |
220 | } | 249 | } |
221 | 250 | ||
222 | - private void processDeviceAdded(Device device) { | ||
223 | - log.debug("device {} is added", device.id()); | ||
224 | - } | ||
225 | - | ||
226 | private void processPortUpdated(Device device, Port port) { | 251 | private void processPortUpdated(Device device, Port port) { |
227 | String portName = port.annotations().value(PORTNAME); | 252 | String portName = port.annotations().value(PORTNAME); |
228 | synchronized (openstackPortInfoMap) { | 253 | synchronized (openstackPortInfoMap) { |
... | @@ -230,7 +255,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -230,7 +255,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
230 | if (port.isEnabled()) { | 255 | if (port.isEnabled()) { |
231 | OpenstackSwitchingRulePopulator rulePopulator = | 256 | OpenstackSwitchingRulePopulator rulePopulator = |
232 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, | 257 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, |
233 | - deviceService, openstackService, driverService); | 258 | + deviceService, openstackService, driverService, config); |
234 | 259 | ||
235 | rulePopulator.populateSwitchingRules(device, port); | 260 | rulePopulator.populateSwitchingRules(device, port); |
236 | OpenstackPort openstackPort = rulePopulator.openstackPort(port); | 261 | OpenstackPort openstackPort = rulePopulator.openstackPort(port); |
... | @@ -244,10 +269,10 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -244,10 +269,10 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
244 | 269 | ||
245 | //In case portupdate event is driven by vm shutoff from openstack | 270 | //In case portupdate event is driven by vm shutoff from openstack |
246 | } else if (!port.isEnabled() && openstackPortInfoMap.containsKey(portName)) { | 271 | } else if (!port.isEnabled() && openstackPortInfoMap.containsKey(portName)) { |
247 | - log.debug("Flowrules according to the port {} were removed", port.number().toString()); | 272 | + log.debug("Flowrules according to the port {} were removed", port.number()); |
248 | OpenstackSwitchingRulePopulator rulePopulator = | 273 | OpenstackSwitchingRulePopulator rulePopulator = |
249 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, | 274 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, |
250 | - deviceService, openstackService, driverService); | 275 | + deviceService, openstackService, driverService, config); |
251 | rulePopulator.removeSwitchingRules(port, openstackPortInfoMap); | 276 | rulePopulator.removeSwitchingRules(port, openstackPortInfoMap); |
252 | openstackPortInfoMap.get(portName).securityGroups().stream().forEach( | 277 | openstackPortInfoMap.get(portName).securityGroups().stream().forEach( |
253 | sgId -> sgRulePopulator.removeSecurityGroupRules(device.id(), sgId, | 278 | sgId -> sgRulePopulator.removeSecurityGroupRules(device.id(), sgId, |
... | @@ -259,14 +284,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -259,14 +284,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
259 | } | 284 | } |
260 | } | 285 | } |
261 | 286 | ||
262 | - private void processPortRemoved(Device device, Port port) { | 287 | + private void processPortRemoved(Port port) { |
263 | log.debug("port {} is removed", port.toString()); | 288 | log.debug("port {} is removed", port.toString()); |
264 | } | 289 | } |
265 | 290 | ||
266 | private void initializeFlowRules() { | 291 | private void initializeFlowRules() { |
267 | OpenstackSwitchingRulePopulator rulePopulator = | 292 | OpenstackSwitchingRulePopulator rulePopulator = |
268 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, | 293 | new OpenstackSwitchingRulePopulator(appId, flowObjectiveService, |
269 | - deviceService, openstackService, driverService); | 294 | + deviceService, openstackService, driverService, config); |
270 | 295 | ||
271 | Collection<OpenstackNetwork> networks = openstackService.networks(); | 296 | Collection<OpenstackNetwork> networks = openstackService.networks(); |
272 | Collection<OpenstackSubnet> subnets = openstackService.subnets(); | 297 | Collection<OpenstackSubnet> subnets = openstackService.subnets(); |
... | @@ -336,16 +361,8 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -336,16 +361,8 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
336 | }); | 361 | }); |
337 | } | 362 | } |
338 | 363 | ||
339 | - private void processHostRemoved(Host host) { | ||
340 | - log.debug("host {} was removed", host.toString()); | ||
341 | - } | ||
342 | - | ||
343 | private void registerDhcpInfo(OpenstackPort openstackPort) { | 364 | private void registerDhcpInfo(OpenstackPort openstackPort) { |
344 | - Ip4Address ip4Address; | 365 | + Ip4Address ip4Address, subnetMask, gatewayIPAddress, dhcpServer, domainServer; |
345 | - Ip4Address subnetMask; | ||
346 | - Ip4Address gatewayIPAddress; | ||
347 | - Ip4Address dhcpServer; | ||
348 | - Ip4Address domainServer; | ||
349 | OpenstackSubnet openstackSubnet; | 366 | OpenstackSubnet openstackSubnet; |
350 | 367 | ||
351 | ip4Address = (Ip4Address) openstackPort.fixedIps().values().stream().findFirst().orElse(null); | 368 | ip4Address = (Ip4Address) openstackPort.fixedIps().values().stream().findFirst().orElse(null); |
... | @@ -359,22 +376,18 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -359,22 +376,18 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
359 | dhcpServer = gatewayIPAddress; | 376 | dhcpServer = gatewayIPAddress; |
360 | // TODO: supports multiple DNS servers | 377 | // TODO: supports multiple DNS servers |
361 | if (openstackSubnet.dnsNameservers().isEmpty()) { | 378 | if (openstackSubnet.dnsNameservers().isEmpty()) { |
362 | - domainServer = Ip4Address.valueOf("8.8.8.8"); | 379 | + domainServer = Ip4Address.valueOf(DNS_SERVER_IP); |
363 | } else { | 380 | } else { |
364 | domainServer = openstackSubnet.dnsNameservers().get(0); | 381 | domainServer = openstackSubnet.dnsNameservers().get(0); |
365 | } | 382 | } |
366 | - List<Ip4Address> options = Lists.newArrayList(); | 383 | + List<Ip4Address> options = ImmutableList.of(subnetMask, dhcpServer, gatewayIPAddress, domainServer); |
367 | - options.add(subnetMask); | ||
368 | - options.add(dhcpServer); | ||
369 | - options.add(gatewayIPAddress); | ||
370 | - options.add(domainServer); | ||
371 | 384 | ||
372 | dhcpService.setStaticMapping(openstackPort.macAddress(), ip4Address, true, options); | 385 | dhcpService.setStaticMapping(openstackPort.macAddress(), ip4Address, true, options); |
373 | } | 386 | } |
374 | 387 | ||
375 | private byte[] buildSubnetMask(String cidr) { | 388 | private byte[] buildSubnetMask(String cidr) { |
376 | int prefix; | 389 | int prefix; |
377 | - String[] parts = cidr.split("/"); | 390 | + String[] parts = cidr.split(FORWARD_SLASH); |
378 | prefix = Integer.parseInt(parts[1]); | 391 | prefix = Integer.parseInt(parts[1]); |
379 | int mask = 0xffffffff << (32 - prefix); | 392 | int mask = 0xffffffff << (32 - prefix); |
380 | byte[] bytes = new byte[]{(byte) (mask >>> 24), | 393 | byte[] bytes = new byte[]{(byte) (mask >>> 24), |
... | @@ -406,7 +419,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -406,7 +419,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
406 | 419 | ||
407 | @Override | 420 | @Override |
408 | public void event(HostEvent hostEvent) { | 421 | public void event(HostEvent hostEvent) { |
409 | - deviceEventExcutorService.execute(new InternalEventHandler(hostEvent)); | 422 | + deviceEventExecutorService.execute(new InternalEventHandler(hostEvent)); |
410 | } | 423 | } |
411 | } | 424 | } |
412 | 425 | ||
... | @@ -414,7 +427,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -414,7 +427,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
414 | 427 | ||
415 | @Override | 428 | @Override |
416 | public void event(DeviceEvent deviceEvent) { | 429 | public void event(DeviceEvent deviceEvent) { |
417 | - deviceEventExcutorService.execute(new InternalEventHandler(deviceEvent)); | 430 | + deviceEventExecutorService.execute(new InternalEventHandler(deviceEvent)); |
418 | } | 431 | } |
419 | } | 432 | } |
420 | 433 | ||
... | @@ -434,22 +447,22 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -434,22 +447,22 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
434 | 447 | ||
435 | switch (deviceEvent.type()) { | 448 | switch (deviceEvent.type()) { |
436 | case DEVICE_ADDED: | 449 | case DEVICE_ADDED: |
437 | - processDeviceAdded((Device) deviceEvent.subject()); | 450 | + log.debug("device {} is added", deviceEvent.subject().id()); |
438 | break; | 451 | break; |
439 | case DEVICE_AVAILABILITY_CHANGED: | 452 | case DEVICE_AVAILABILITY_CHANGED: |
440 | - Device device = (Device) deviceEvent.subject(); | 453 | + Device device = deviceEvent.subject(); |
441 | if (deviceService.isAvailable(device.id())) { | 454 | if (deviceService.isAvailable(device.id())) { |
442 | - processDeviceAdded(device); | 455 | + log.debug("device {} is added", device.id()); |
443 | } | 456 | } |
444 | break; | 457 | break; |
445 | case PORT_ADDED: | 458 | case PORT_ADDED: |
446 | - processPortUpdated((Device) deviceEvent.subject(), deviceEvent.port()); | 459 | + processPortUpdated(deviceEvent.subject(), deviceEvent.port()); |
447 | break; | 460 | break; |
448 | case PORT_UPDATED: | 461 | case PORT_UPDATED: |
449 | - processPortUpdated((Device) deviceEvent.subject(), deviceEvent.port()); | 462 | + processPortUpdated(deviceEvent.subject(), deviceEvent.port()); |
450 | break; | 463 | break; |
451 | case PORT_REMOVED: | 464 | case PORT_REMOVED: |
452 | - processPortRemoved((Device) deviceEvent.subject(), deviceEvent.port()); | 465 | + processPortRemoved(deviceEvent.port()); |
453 | break; | 466 | break; |
454 | default: | 467 | default: |
455 | log.debug("Unsupported deviceEvent type {}", deviceEvent.type().toString()); | 468 | log.debug("Unsupported deviceEvent type {}", deviceEvent.type().toString()); |
... | @@ -460,7 +473,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -460,7 +473,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
460 | 473 | ||
461 | switch (hostEvent.type()) { | 474 | switch (hostEvent.type()) { |
462 | case HOST_REMOVED: | 475 | case HOST_REMOVED: |
463 | - processHostRemoved((Host) hostEvent.subject()); | 476 | + log.debug("host {} was removed", hostEvent.subject().toString()); |
464 | break; | 477 | break; |
465 | default: | 478 | default: |
466 | log.debug("Unsupported hostEvent type {}", hostEvent.type().toString()); | 479 | log.debug("Unsupported hostEvent type {}", hostEvent.type().toString()); |
... | @@ -469,4 +482,34 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { | ... | @@ -469,4 +482,34 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { |
469 | } | 482 | } |
470 | } | 483 | } |
471 | } | 484 | } |
485 | + | ||
486 | + private void readConfiguration() { | ||
487 | + config = configService.getConfig(appId, OpenstackSwitchingConfig.class); | ||
488 | + if (config == null) { | ||
489 | + log.error("No configuration found"); | ||
490 | + return; | ||
491 | + } | ||
492 | + | ||
493 | + arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService); | ||
494 | + sgRulePopulator = new OpenstackSecurityGroupRulePopulator(appId, openstackService, flowObjectiveService); | ||
495 | + | ||
496 | + initializeFlowRules(); | ||
497 | + } | ||
498 | + | ||
499 | + private class InternalConfigListener implements NetworkConfigListener { | ||
500 | + | ||
501 | + @Override | ||
502 | + public void event(NetworkConfigEvent event) { | ||
503 | + if (!event.configClass().equals(OpenstackSwitchingConfig.class)) { | ||
504 | + return; | ||
505 | + } | ||
506 | + | ||
507 | + if (event.type().equals(NetworkConfigEvent.Type.CONFIG_ADDED) || | ||
508 | + event.type().equals(NetworkConfigEvent.Type.CONFIG_UPDATED)) { | ||
509 | + configEventExecutorService.execute(OpenstackSwitchingManager.this::readConfiguration); | ||
510 | + | ||
511 | + | ||
512 | + } | ||
513 | + } | ||
514 | + } | ||
472 | } | 515 | } | ... | ... |
... | @@ -59,11 +59,13 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -59,11 +59,13 @@ public class OpenstackSwitchingRulePopulator { |
59 | .getLogger(OpenstackSwitchingRulePopulator.class); | 59 | .getLogger(OpenstackSwitchingRulePopulator.class); |
60 | private static final int SWITCHING_RULE_PRIORITY = 30000; | 60 | private static final int SWITCHING_RULE_PRIORITY = 30000; |
61 | private static final int TUNNELTAG_RULE_PRIORITY = 30000; | 61 | private static final int TUNNELTAG_RULE_PRIORITY = 30000; |
62 | - | 62 | + private static final String PORT_NAME = "portName"; |
63 | + private static final String TUNNEL_DST = "tunnelDst"; | ||
63 | private FlowObjectiveService flowObjectiveService; | 64 | private FlowObjectiveService flowObjectiveService; |
64 | private DriverService driverService; | 65 | private DriverService driverService; |
65 | private DeviceService deviceService; | 66 | private DeviceService deviceService; |
66 | private ApplicationId appId; | 67 | private ApplicationId appId; |
68 | + private OpenstackSwitchingConfig config; | ||
67 | 69 | ||
68 | private Collection<OpenstackNetwork> openstackNetworkList; | 70 | private Collection<OpenstackNetwork> openstackNetworkList; |
69 | private Collection<OpenstackPort> openstackPortList; | 71 | private Collection<OpenstackPort> openstackPortList; |
... | @@ -76,16 +78,19 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -76,16 +78,19 @@ public class OpenstackSwitchingRulePopulator { |
76 | * @param deviceService DeviceService reference | 78 | * @param deviceService DeviceService reference |
77 | * @param openstackService openstack interface service | 79 | * @param openstackService openstack interface service |
78 | * @param driverService DriverService reference | 80 | * @param driverService DriverService reference |
81 | + * @param config OpenstackRoutingConfig | ||
79 | */ | 82 | */ |
80 | public OpenstackSwitchingRulePopulator(ApplicationId appId, | 83 | public OpenstackSwitchingRulePopulator(ApplicationId appId, |
81 | FlowObjectiveService flowObjectiveService, | 84 | FlowObjectiveService flowObjectiveService, |
82 | DeviceService deviceService, | 85 | DeviceService deviceService, |
83 | OpenstackInterfaceService openstackService, | 86 | OpenstackInterfaceService openstackService, |
84 | - DriverService driverService) { | 87 | + DriverService driverService, |
88 | + OpenstackSwitchingConfig config) { | ||
85 | this.flowObjectiveService = flowObjectiveService; | 89 | this.flowObjectiveService = flowObjectiveService; |
86 | this.deviceService = deviceService; | 90 | this.deviceService = deviceService; |
87 | this.driverService = driverService; | 91 | this.driverService = driverService; |
88 | this.appId = appId; | 92 | this.appId = appId; |
93 | + this.config = config; | ||
89 | 94 | ||
90 | openstackNetworkList = openstackService.networks(); | 95 | openstackNetworkList = openstackService.networks(); |
91 | openstackPortList = openstackService.ports(); | 96 | openstackPortList = openstackService.ports(); |
... | @@ -111,8 +116,8 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -111,8 +116,8 @@ public class OpenstackSwitchingRulePopulator { |
111 | * @param port port info of the VM | 116 | * @param port port info of the VM |
112 | */ | 117 | */ |
113 | private void populateFlowRulesForTunnelTag(Device device, Port port) { | 118 | private void populateFlowRulesForTunnelTag(Device device, Port port) { |
114 | - Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName")); | 119 | + Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value(PORT_NAME)); |
115 | - String portName = port.annotations().value("portName"); | 120 | + String portName = port.annotations().value(PORT_NAME); |
116 | String vni = getVniForPort(portName); | 121 | String vni = getVniForPort(portName); |
117 | 122 | ||
118 | if (vmIp != null) { | 123 | if (vmIp != null) { |
... | @@ -148,8 +153,8 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -148,8 +153,8 @@ public class OpenstackSwitchingRulePopulator { |
148 | * @param port port info of the VM | 153 | * @param port port info of the VM |
149 | */ | 154 | */ |
150 | private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) { | 155 | private void populateFlowRulesForTrafficToSameCnode(Device device, Port port) { |
151 | - Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value("portName")); | 156 | + Ip4Address vmIp = getFixedIpAddressForPort(port.annotations().value(PORT_NAME)); |
152 | - String portName = port.annotations().value("portName"); | 157 | + String portName = port.annotations().value(PORT_NAME); |
153 | String vni = getVniForPort(portName); | 158 | String vni = getVniForPort(portName); |
154 | 159 | ||
155 | if (vmIp != null) { | 160 | if (vmIp != null) { |
... | @@ -197,24 +202,27 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -197,24 +202,27 @@ public class OpenstackSwitchingRulePopulator { |
197 | * @param port port information of the VM | 202 | * @param port port information of the VM |
198 | */ | 203 | */ |
199 | private void populateFlowRulesForTrafficToDifferentCnode(Device device, Port port) { | 204 | private void populateFlowRulesForTrafficToDifferentCnode(Device device, Port port) { |
200 | - String portName = port.annotations().value("portName"); | 205 | + String portName = port.annotations().value(PORT_NAME); |
201 | - String channelId = device.annotations().value("channelId"); | ||
202 | - Ip4Address hostIpAddress = Ip4Address.valueOf(channelId.split(":")[0]); | ||
203 | Ip4Address fixedIp = getFixedIpAddressForPort(portName); | 206 | Ip4Address fixedIp = getFixedIpAddressForPort(portName); |
204 | String vni = getVniForPort(portName); | 207 | String vni = getVniForPort(portName); |
208 | + Ip4Address hostDpIpAddress = config.nodes().get(device.id()); | ||
209 | + | ||
210 | + if (hostDpIpAddress == null) { | ||
211 | + log.debug("There's no openstack node information for device id {}", device.id().toString()); | ||
212 | + return; | ||
213 | + } | ||
214 | + | ||
205 | deviceService.getAvailableDevices().forEach(d -> { | 215 | deviceService.getAvailableDevices().forEach(d -> { |
206 | if (!d.equals(device)) { | 216 | if (!d.equals(device)) { |
207 | deviceService.getPorts(d.id()).forEach(p -> { | 217 | deviceService.getPorts(d.id()).forEach(p -> { |
208 | - String pName = p.annotations().value("portName"); | 218 | + String pName = p.annotations().value(PORT_NAME); |
209 | if (!p.equals(port) && vni.equals(getVniForPort(pName))) { | 219 | if (!p.equals(port) && vni.equals(getVniForPort(pName))) { |
210 | - String cidx = d.annotations().value("channelId"); | 220 | + Ip4Address hostxDpIpAddress = config.nodes().get(d.id()); |
211 | - Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]); | 221 | + |
212 | Ip4Address fixedIpx = getFixedIpAddressForPort(pName); | 222 | Ip4Address fixedIpx = getFixedIpAddressForPort(pName); |
213 | - if (port.isEnabled() || | 223 | + if (port.isEnabled()) { |
214 | - port.annotations().value("portName").startsWith( | 224 | + setVxLanFlowRule(vni, device.id(), hostxDpIpAddress, fixedIpx); |
215 | - OpenstackSwitchingManager.PORTNAME_PREFIX_ROUTER)) { | 225 | + setVxLanFlowRule(vni, d.id(), hostDpIpAddress, fixedIp); |
216 | - setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx); | ||
217 | - setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp); | ||
218 | } | 226 | } |
219 | } | 227 | } |
220 | }); | 228 | }); |
... | @@ -259,7 +267,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -259,7 +267,7 @@ public class OpenstackSwitchingRulePopulator { |
259 | * @return OpenstackPort reference, or null when not found | 267 | * @return OpenstackPort reference, or null when not found |
260 | */ | 268 | */ |
261 | public OpenstackPort openstackPort(Port port) { | 269 | public OpenstackPort openstackPort(Port port) { |
262 | - String uuid = port.annotations().value("portName").substring(3); | 270 | + String uuid = port.annotations().value(PORT_NAME).substring(3); |
263 | return openstackPortList.stream().filter(p -> p.id().startsWith(uuid)) | 271 | return openstackPortList.stream().filter(p -> p.id().startsWith(uuid)) |
264 | .findAny().orElse(null); | 272 | .findAny().orElse(null); |
265 | } | 273 | } |
... | @@ -273,7 +281,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -273,7 +281,7 @@ public class OpenstackSwitchingRulePopulator { |
273 | public void removeSwitchingRules(Port removedPort, Map<String, | 281 | public void removeSwitchingRules(Port removedPort, Map<String, |
274 | OpenstackPortInfo> openstackPortInfoMap) { | 282 | OpenstackPortInfo> openstackPortInfoMap) { |
275 | OpenstackPortInfo openstackPortInfo = openstackPortInfoMap | 283 | OpenstackPortInfo openstackPortInfo = openstackPortInfoMap |
276 | - .get(removedPort.annotations().value("portName")); | 284 | + .get(removedPort.annotations().value(PORT_NAME)); |
277 | 285 | ||
278 | DeviceId deviceId = openstackPortInfo.deviceId(); | 286 | DeviceId deviceId = openstackPortInfo.deviceId(); |
279 | Ip4Address vmIp = openstackPortInfo.ip(); | 287 | Ip4Address vmIp = openstackPortInfo.ip(); |
... | @@ -397,7 +405,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -397,7 +405,7 @@ public class OpenstackSwitchingRulePopulator { |
397 | Map<String, OpenstackPortInfo> openstackPortInfoMap) { | 405 | Map<String, OpenstackPortInfo> openstackPortInfoMap) { |
398 | 406 | ||
399 | for (Map.Entry<String, OpenstackPortInfo> entry : openstackPortInfoMap.entrySet()) { | 407 | for (Map.Entry<String, OpenstackPortInfo> entry : openstackPortInfoMap.entrySet()) { |
400 | - if (!removedPort.annotations().value("portName").equals(entry.getKey())) { | 408 | + if (!removedPort.annotations().value(PORT_NAME).equals(entry.getKey())) { |
401 | if (entry.getValue().vni() == vni && entry.getValue().deviceId().equals(deviceId)) { | 409 | if (entry.getValue().vni() == vni && entry.getValue().deviceId().equals(deviceId)) { |
402 | return true; | 410 | return true; |
403 | } | 411 | } |
... | @@ -469,7 +477,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -469,7 +477,7 @@ public class OpenstackSwitchingRulePopulator { |
469 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type()); | 477 | ExtensionTreatmentType.ExtensionTreatmentTypes.NICIRA_SET_TUNNEL_DST.type()); |
470 | 478 | ||
471 | try { | 479 | try { |
472 | - extensionInstruction.setPropertyValue("tunnelDst", hostIp); | 480 | + extensionInstruction.setPropertyValue(TUNNEL_DST, hostIp); |
473 | } catch (ExtensionPropertyException e) { | 481 | } catch (ExtensionPropertyException e) { |
474 | log.error("Error setting Nicira extension setting {}", e); | 482 | log.error("Error setting Nicira extension setting {}", e); |
475 | } | 483 | } |
... | @@ -479,7 +487,7 @@ public class OpenstackSwitchingRulePopulator { | ... | @@ -479,7 +487,7 @@ public class OpenstackSwitchingRulePopulator { |
479 | 487 | ||
480 | private PortNumber getTunnelPort(DeviceId deviceId) { | 488 | private PortNumber getTunnelPort(DeviceId deviceId) { |
481 | Port port = deviceService.getPorts(deviceId).stream() | 489 | Port port = deviceService.getPorts(deviceId).stream() |
482 | - .filter(p -> p.annotations().value("portName").equals( | 490 | + .filter(p -> p.annotations().value(PORT_NAME).equals( |
483 | OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL)) | 491 | OpenstackSwitchingManager.PORTNAME_PREFIX_TUNNEL)) |
484 | .findAny().orElse(null); | 492 | .findAny().orElse(null); |
485 | 493 | ... | ... |
-
Please register or login to post a comment