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
275 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; | ... | ... |
1 | { | 1 | { |
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 | - } | 9 | + "nodes" : [ |
10 | - }, | 10 | + { |
11 | - "org.onosproject.openstacknode" : { | 11 | + "dataPlaneIp" : "192.168.57.103", |
12 | - "openstacknode" : { | 12 | + "bridgeId" : "of:0000000000000001" |
13 | - "nodes" : [ | 13 | + }, |
14 | - { | 14 | + { |
15 | - "hostname" : "compute-01", | 15 | + "dataPlaneIp" : "192.168.57.104", |
16 | - "ovsdbIp" : "192.168.56.112", | 16 | + "bridgeId" : "of:0000000000000002" |
17 | - "ovsdbPort" : "6640", | 17 | + }, |
18 | - "bridgeId" : "of:0000000000000001", | 18 | + { |
19 | - "openstackNodeType" : "COMPUTENODE" | 19 | + "dataPlaneIp" : "192.168.57.105", |
20 | - }, | 20 | + "bridgeId" : "of:0000000000000003" |
21 | - { | 21 | + } |
22 | - "hostname" : "compute-02", | 22 | + ] |
23 | - "ovsdbIp" : "192.168.56.113", | 23 | + } |
24 | - "ovsdbPort" : "6640", | ||
25 | - "bridgeId" : "of:0000000000000002", | ||
26 | - "openstackNodeType" : "COMPUTENODE" | ||
27 | - }, | ||
28 | - { | ||
29 | - "hostname" : "network", | ||
30 | - "ovsdbIp" : "192.168.56.114", | ||
31 | - "ovsdbPort" : "6640", | ||
32 | - "bridgeId" : "of:0000000000000003", | ||
33 | - "openstackNodeType" : "GATEWAYNODE", | ||
34 | - "gatewayExternalInterfaceName" : "veth0", | ||
35 | - "gatewayExternalInterfaceMac" : "be:15:c6:b0:df:9f" | ||
36 | - } | ||
37 | - ] | ||
38 | - } | ||
39 | - }, | ||
40 | - "org.onosproject.openstackinterface" : { | ||
41 | - "openstackinterface" : { | ||
42 | - "neutron_server" : "http://192.168.56.111:9696/v2.0/", | ||
43 | - "keystone_server" : "http://192.168.56.111:5000/v2.0/", | ||
44 | - "user_name" : "admin", | ||
45 | - "password" : "nova" | ||
46 | - } | ||
47 | - } | ||
48 | }, | 24 | }, |
49 | - "devices" : { | 25 | + "org.onosproject.openstackswitching" : { |
50 | - "of:0000000000000001" : { | 26 | + "openstackswitching" : { |
51 | - "basic" : { | 27 | + "nodes" : [ |
52 | - "driver" : "sona" | 28 | + { |
53 | - } | 29 | + "dataPlaneIp" : "192.168.57.103", |
54 | - }, | 30 | + "bridgeId" : "of:0000000000000001" |
55 | - "of:0000000000000002" : { | 31 | + }, |
56 | - "basic" : { | 32 | + { |
57 | - "driver" : "sona" | 33 | + "dataPlaneIp" : "192.168.57.104", |
58 | - } | 34 | + "bridgeId" : "of:0000000000000002" |
59 | - } | 35 | + }, |
36 | + { | ||
37 | + "dataPlaneIp" : "192.168.57.105", | ||
38 | + "bridgeId" : "of:0000000000000003" | ||
39 | + } | ||
40 | + ] | ||
41 | + } | ||
42 | + }, | ||
43 | + "org.onosproject.openstacknode" : { | ||
44 | + "openstacknode" : { | ||
45 | + "nodes" : [ | ||
46 | + { | ||
47 | + "hostname" : "compute-01", | ||
48 | + "ovsdbIp" : "192.168.56.121", | ||
49 | + "ovsdbPort" : "6640", | ||
50 | + "bridgeId" : "of:0000000000000001", | ||
51 | + "openstackNodeType" : "COMPUTENODE" | ||
52 | + }, | ||
53 | + { | ||
54 | + "hostname" : "compute-02", | ||
55 | + "ovsdbIp" : "192.168.56.122", | ||
56 | + "ovsdbPort" : "6640", | ||
57 | + "bridgeId" : "of:0000000000000002", | ||
58 | + "openstackNodeType" : "COMPUTENODE" | ||
59 | + }, | ||
60 | + { | ||
61 | + "hostname" : "network", | ||
62 | + "ovsdbIp" : "192.168.56.114", | ||
63 | + "ovsdbPort" : "6640", | ||
64 | + "bridgeId" : "of:0000000000000003", | ||
65 | + "openstackNodeType" : "GATEWAYNODE", | ||
66 | + "gatewayExternalInterfaceName" : "veth0", | ||
67 | + "gatewayExternalInterfaceMac" : "96:87:bc:64:99:ad" | ||
68 | + } | ||
69 | + ] | ||
70 | + } | ||
71 | + }, | ||
72 | + "org.onosproject.openstackinterface" : { | ||
73 | + "openstackinterface" : { | ||
74 | + "neutron_server" : "http://192.168.56.118:9696/v2.0/", | ||
75 | + "keystone_server" : "http://192.168.56.118:5000/v2.0/", | ||
76 | + "user_name" : "admin", | ||
77 | + "password" : "rocks" | ||
78 | + } | ||
79 | + } | ||
80 | + }, | ||
81 | + "devices" : { | ||
82 | + "of:0000000000000001" : { | ||
83 | + "basic" : { | ||
84 | + "driver" : "sona" | ||
85 | + } | ||
86 | + }, | ||
87 | + "of:0000000000000002" : { | ||
88 | + "basic" : { | ||
89 | + "driver" : "sona" | ||
90 | + } | ||
60 | } | 91 | } |
92 | + } | ||
61 | } | 93 | } |
62 | 94 | ... | ... |
... | @@ -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 { |
385 | + OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), | ||
386 | + Ip4Address.valueOf(iPacket.getSourceAddress())); | ||
387 | + l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, | ||
388 | + portNum, openstackPort, port.get(), config)); | ||
379 | } | 389 | } |
380 | - OpenstackPort openstackPort = getOpenstackPort(ethernet.getSourceMAC(), | ||
381 | - Ip4Address.valueOf(iPacket.getSourceAddress())); | ||
382 | - l3EventExecutorService.execute(new OpenstackPnatHandler(rulePopulator, context, | ||
383 | - portNum, openstackPort, port, config)); | ||
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() | 454 | + .findAny() |
455 | - .orElse(null) | 455 | + .get() |
456 | .equals(externalIp)) | 456 | .equals(externalIp)) |
457 | - .findAny() | 457 | + .findAny(); |
458 | - .orElse(null); | ||
459 | - return checkNotNull(router); | ||
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 | +} |
This diff is collapsed. Click to expand it.
... | @@ -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