Daniel Park
Committed by Gerrit Code Review

[ONOS-3946] Implement IcmpHandler for OpenstackRoutingService

- Process Icmp packet sent from Host to external network for OpenstackGateway Node
- Process Arp packet sent from physical  router to gateway

Change-Id: Ifcde71a9ca10180682811c9e1bcf58f991b36443
...@@ -68,7 +68,6 @@ public class OpenstackRouterCodec extends JsonCodec<OpenstackRouter> { ...@@ -68,7 +68,6 @@ public class OpenstackRouterCodec extends JsonCodec<OpenstackRouter> {
68 String tenantId = checkNotNull(routerInfo.path(TENANT_ID).asText()); 68 String tenantId = checkNotNull(routerInfo.path(TENANT_ID).asText());
69 String id = checkNotNull(routerInfo.path(ID).asText()); 69 String id = checkNotNull(routerInfo.path(ID).asText());
70 String name = checkNotNull(routerInfo.path(NAME).asText()); 70 String name = checkNotNull(routerInfo.path(NAME).asText());
71 - String status = checkNotNull(routerInfo.path(STATUS).asText());
72 String adminStateUp = checkNotNull(routerInfo.path(ADMIN_STATE_UP).asText()); 71 String adminStateUp = checkNotNull(routerInfo.path(ADMIN_STATE_UP).asText());
73 72
74 OpenstackExternalGateway.Builder osExtBuiler = new OpenstackExternalGateway.Builder(); 73 OpenstackExternalGateway.Builder osExtBuiler = new OpenstackExternalGateway.Builder();
...@@ -98,7 +97,7 @@ public class OpenstackRouterCodec extends JsonCodec<OpenstackRouter> { ...@@ -98,7 +97,7 @@ public class OpenstackRouterCodec extends JsonCodec<OpenstackRouter> {
98 .tenantId(tenantId) 97 .tenantId(tenantId)
99 .id(id) 98 .id(id)
100 .name(name) 99 .name(name)
101 - .status(OpenstackRouter.RouterStatus.valueOf(status)) 100 + .status(OpenstackRouter.RouterStatus.ACTIVE)
102 .adminStateUp(Boolean.valueOf(adminStateUp)) 101 .adminStateUp(Boolean.valueOf(adminStateUp))
103 .gatewayExternalInfo(osExtBuiler.build()); 102 .gatewayExternalInfo(osExtBuiler.build());
104 103
......
...@@ -27,12 +27,13 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -27,12 +27,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
27 /** 27 /**
28 * Contains OpenstackPort Information. 28 * Contains OpenstackPort Information.
29 */ 29 */
30 -public class OpenstackPortInfo { 30 +public final class OpenstackPortInfo {
31 private final Ip4Address hostIp; 31 private final Ip4Address hostIp;
32 private final MacAddress hostMac; 32 private final MacAddress hostMac;
33 private final DeviceId deviceId; 33 private final DeviceId deviceId;
34 private final long vni; 34 private final long vni;
35 private final Ip4Address gatewayIP; 35 private final Ip4Address gatewayIP;
36 + private final String networkId;
36 private final Collection<String> securityGroups; 37 private final Collection<String> securityGroups;
37 38
38 /** 39 /**
...@@ -46,12 +47,13 @@ public class OpenstackPortInfo { ...@@ -46,12 +47,13 @@ public class OpenstackPortInfo {
46 * @param securityGroups security group list 47 * @param securityGroups security group list
47 */ 48 */
48 public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni, 49 public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni,
49 - Ip4Address gatewayIP, Collection<String> securityGroups) { 50 + Ip4Address gatewayIP, String networkId, Collection<String> securityGroups) {
50 this.hostIp = hostIp; 51 this.hostIp = hostIp;
51 this.hostMac = hostMac; 52 this.hostMac = hostMac;
52 this.deviceId = deviceId; 53 this.deviceId = deviceId;
53 this.vni = vni; 54 this.vni = vni;
54 this.gatewayIP = gatewayIP; 55 this.gatewayIP = gatewayIP;
56 + this.networkId = networkId;
55 this.securityGroups = securityGroups; 57 this.securityGroups = securityGroups;
56 } 58 }
57 59
...@@ -101,6 +103,15 @@ public class OpenstackPortInfo { ...@@ -101,6 +103,15 @@ public class OpenstackPortInfo {
101 } 103 }
102 104
103 /** 105 /**
106 + * Returns network ID.
107 + *
108 + * @return network ID
109 + */
110 + public String networkId() {
111 + return networkId;
112 + }
113 +
114 + /**
104 * Returns Security Group ID list. 115 * Returns Security Group ID list.
105 * 116 *
106 * @return list of Security Group ID 117 * @return list of Security Group ID
...@@ -129,11 +140,12 @@ public class OpenstackPortInfo { ...@@ -129,11 +140,12 @@ public class OpenstackPortInfo {
129 private long vni; 140 private long vni;
130 private Ip4Address gatewayIP; 141 private Ip4Address gatewayIP;
131 private Collection<String> securityGroups; 142 private Collection<String> securityGroups;
143 + private String networkId;
132 144
133 /** 145 /**
134 * Sets the IP address of the port. 146 * Sets the IP address of the port.
135 * 147 *
136 - * @param gatewayIP 148 + * @param gatewayIP gateway IP
137 * @return Builder reference 149 * @return Builder reference
138 */ 150 */
139 public Builder setGatewayIP(Ip4Address gatewayIP) { 151 public Builder setGatewayIP(Ip4Address gatewayIP) {
...@@ -142,6 +154,17 @@ public class OpenstackPortInfo { ...@@ -142,6 +154,17 @@ public class OpenstackPortInfo {
142 } 154 }
143 155
144 /** 156 /**
157 + * Sets the network ID.
158 + *
159 + * @param networkId network id
160 + * @return Builder reference
161 + */
162 + public Builder setNetworkId(String networkId) {
163 + this.networkId = checkNotNull(networkId, "networkId cannot be null");
164 + return this;
165 + }
166 +
167 + /**
145 * Sets the host IP address of the port. 168 * Sets the host IP address of the port.
146 * 169 *
147 * @param hostIp host IP address 170 * @param hostIp host IP address
...@@ -202,16 +225,7 @@ public class OpenstackPortInfo { ...@@ -202,16 +225,7 @@ public class OpenstackPortInfo {
202 * @return OpenstackPortInfo reference 225 * @return OpenstackPortInfo reference
203 */ 226 */
204 public OpenstackPortInfo build() { 227 public OpenstackPortInfo build() {
205 - return new OpenstackPortInfo(this); 228 + return new OpenstackPortInfo(hostIp, hostMac, deviceId, vni, gatewayIP, networkId, securityGroups);
206 } 229 }
207 } 230 }
208 -
209 - private OpenstackPortInfo(Builder builder) {
210 - hostIp = builder.hostIp;
211 - hostMac = builder.hostMac;
212 - deviceId = builder.deviceId;
213 - vni = builder.vni;
214 - gatewayIP = builder.gatewayIP;
215 - securityGroups = builder.securityGroups;
216 - }
217 } 231 }
......
1 { 1 {
2 "apps" : { 2 "apps" : {
3 - "org.onosproject.openstackswitching" : { 3 + "org.onosproject.openstackrouting" : {
4 - "openstackswitching" : { 4 + "openstackrouting" : {
5 - "do_not_push_flows" : "false", 5 + "physicalRouterMac" : "2a:a1:8a:89:dd:a4",
6 - "neutron_server" : "http://192.168.56.103:9696/v2.0/", 6 + "gatewayBridgeId" : "of:0000000000000003",
7 - "keystone_server" : "http://192.168.56.103:5000/v2.0/", 7 + "gatewayExternalInterfaceName" : "veth0",
8 - "user_name" : "admin", 8 + "gatewayExternalInterfaceMac" : "be:15:c6:b0:df:9f"
9 - "password" : "nova", 9 + }
10 - "physicalRouterMac" : "00:00:00:00:00:20", 10 + },
11 + "org.onosproject.openstacknode" : {
12 + "openstacknode" : {
11 "nodes" : [ 13 "nodes" : [
12 - { 14 + {
13 - "hostname" : "compute-01", 15 + "hostname" : "compute-01",
14 - "ovsdbIp" : "192.168.56.102", 16 + "ovsdbIp" : "192.168.56.112",
15 - "ovsdbPort" : "6640", 17 + "ovsdbPort" : "6640",
16 - "bridgeId" : "of:0000000000000001", 18 + "bridgeId" : "of:0000000000000001",
17 - "openstackNodeType" : "COMPUTENODE" 19 + "openstackNodeType" : "COMPUTENODE"
18 - }, 20 + },
19 - { 21 + {
20 - "hostname" : "compute-02", 22 + "hostname" : "compute-02",
21 - "ovsdbIp" : "192.168.56.101", 23 + "ovsdbIp" : "192.168.56.113",
22 - "ovsdbPort" : "6640", 24 + "ovsdbPort" : "6640",
23 - "bridgeId" : "of:0000000000000002", 25 + "bridgeId" : "of:0000000000000002",
24 - "openstackNodeType" : "COMPUTENODE" 26 + "openstackNodeType" : "COMPUTENODE"
25 - }, 27 + },
26 - { 28 + {
27 - "hostname" : "network", 29 + "hostname" : "network",
28 - "ovsdbIp" : "192.168.56.106", 30 + "ovsdbIp" : "192.168.56.114",
29 - "ovsdbPort" : "6640", 31 + "ovsdbPort" : "6640",
30 - "bridgeId" : "of:0000000000000003", 32 + "bridgeId" : "of:0000000000000003",
31 - "openstackNodeType" : "GATEWAYNODE", 33 + "openstackNodeType" : "GATEWAYNODE",
32 - "externalIfName" : "eth3", 34 + "gatewayExternalInterfaceName" : "veth0",
33 - "externalIfMacAddress" : "00:00:00:00:00:11" 35 + "gatewayExternalInterfaceMac" : "be:15:c6:b0:df:9f"
34 - } 36 + }
35 ] 37 ]
36 - } 38 + }
37 - } 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 + }
38 }, 48 },
39 "devices" : { 49 "devices" : {
40 "of:0000000000000001" : { 50 "of:0000000000000001" : {
...@@ -49,3 +59,4 @@ ...@@ -49,3 +59,4 @@
49 } 59 }
50 } 60 }
51 } 61 }
62 +
......
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.routing;
17 +
18 +import org.onlab.packet.ARP;
19 +import org.onlab.packet.EthType;
20 +import org.onlab.packet.Ethernet;
21 +import org.onlab.packet.IPv4;
22 +import org.onlab.packet.Ip4Address;
23 +import org.onlab.packet.IpAddress;
24 +import org.onlab.packet.MacAddress;
25 +import org.onosproject.core.ApplicationId;
26 +import org.onosproject.net.DeviceId;
27 +import org.onosproject.net.flow.DefaultTrafficSelector;
28 +import org.onosproject.net.flow.DefaultTrafficTreatment;
29 +import org.onosproject.net.flow.TrafficSelector;
30 +import org.onosproject.net.flow.TrafficTreatment;
31 +import org.onosproject.net.packet.DefaultOutboundPacket;
32 +import org.onosproject.net.packet.PacketContext;
33 +import org.onosproject.net.packet.PacketPriority;
34 +import org.onosproject.net.packet.PacketService;
35 +import org.onosproject.openstackinterface.OpenstackInterfaceService;
36 +import org.onosproject.openstackinterface.OpenstackPort;
37 +import org.slf4j.Logger;
38 +
39 +import java.nio.ByteBuffer;
40 +import java.util.Optional;
41 +
42 +import static com.google.common.base.Preconditions.checkNotNull;
43 +import static org.slf4j.LoggerFactory.getLogger;
44 +
45 +/**
46 + * Handle ARP packet sent from Openstack Gateway nodes.
47 + */
48 +public class OpenstackRoutingArpHandler {
49 + protected final Logger log = getLogger(getClass());
50 +
51 + private final PacketService packetService;
52 + private final OpenstackInterfaceService openstackService;
53 + private final OpenstackRoutingConfig config;
54 + private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway";
55 +
56 + /**
57 + * Default constructor.
58 + *
59 + * @param packetService packet service
60 + * @param openstackService openstackInterface service
61 + * @param config openstackRoutingConfig
62 + */
63 + OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService,
64 + OpenstackRoutingConfig config) {
65 + this.packetService = packetService;
66 + this.openstackService = checkNotNull(openstackService);
67 + this.config = checkNotNull(config);
68 + }
69 +
70 + /**
71 + * Requests ARP packet to GatewayNode.
72 + *
73 + * @param appId application id
74 + */
75 + public void requestPacket(ApplicationId appId) {
76 +
77 + TrafficSelector arpSelector = DefaultTrafficSelector.builder()
78 + .matchEthType(EthType.EtherType.ARP.ethType().toShort())
79 + .build();
80 +
81 + packetService.requestPackets(arpSelector,
82 + PacketPriority.CONTROL,
83 + appId,
84 + Optional.of(DeviceId.deviceId(config.gatewayBridgeId())));
85 + }
86 +
87 + /**
88 + * Handles ARP packet.
89 + *
90 + * @param context packet context
91 + * @param ethernet ethernet
92 + */
93 + public void processArpPacketFromRouter(PacketContext context, Ethernet ethernet) {
94 + checkNotNull(context, "context can not be null");
95 + checkNotNull(ethernet, "ethernet can not be null");
96 +
97 + log.info("arpEvent called from {} to {}",
98 + Ip4Address.valueOf(((IPv4) ethernet.getPayload()).getSourceAddress()).toString(),
99 + Ip4Address.valueOf(((IPv4) ethernet.getPayload()).getDestinationAddress()).toString());
100 + ARP arp = (ARP) ethernet.getPayload();
101 +
102 + if (arp.getOpCode() != ARP.OP_REQUEST) {
103 + return;
104 + }
105 +
106 + IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress());
107 + MacAddress targetMac = getTargetMacForTargetIp(targetIp.getIp4Address());
108 +
109 + if (targetMac == MacAddress.NONE) {
110 + return;
111 + }
112 +
113 + Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(),
114 + targetMac, ethernet);
115 +
116 + TrafficTreatment treatment = DefaultTrafficTreatment.builder()
117 + .setOutput(context.inPacket().receivedFrom().port())
118 + .build();
119 +
120 + packetService.emit(new DefaultOutboundPacket(
121 + context.inPacket().receivedFrom().deviceId(),
122 + treatment,
123 + ByteBuffer.wrap(ethReply.serialize())));
124 + }
125 +
126 + private MacAddress getTargetMacForTargetIp(Ip4Address targetIp) {
127 + OpenstackPort port = openstackService.ports().stream()
128 + .filter(p -> p.deviceOwner().equals(NETWORK_ROUTER_GATEWAY))
129 + .filter(p -> p.fixedIps().containsValue(targetIp.getIp4Address()))
130 + .findAny().orElse(null);
131 +
132 + if (port == null) {
133 + return MacAddress.NONE;
134 + }
135 + return port.macAddress();
136 + }
137 +}
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.routing;
17 +
18 +import org.onosproject.core.ApplicationId;
19 +import org.onosproject.net.config.Config;
20 +import org.slf4j.Logger;
21 +
22 +import static org.slf4j.LoggerFactory.getLogger;
23 +
24 +/**
25 + * Configuration object for OpenstackRouting service.
26 + */
27 +public class OpenstackRoutingConfig extends Config<ApplicationId> {
28 + protected final Logger log = getLogger(getClass());
29 +
30 + public static final String PHYSICAL_ROUTER_MAC = "physicalRouterMac";
31 + public static final String GATEWAY_BRIDGE_ID = "gatewayBridgeId";
32 + public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName";
33 + public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac";
34 +
35 + /**
36 + * Returns physical router mac.
37 + *
38 + * @return physical router mac
39 + */
40 + public String physicalRouterMac() {
41 + return this.get("physicalRouterMac", "");
42 + }
43 +
44 + /**
45 + * Returns gateway's bridge id.
46 + *
47 + * @return bridge id
48 + */
49 + public String gatewayBridgeId() {
50 + return this.get("gatewayBridgeId", "");
51 + }
52 +
53 + /**
54 + * Returns gateway's external interface name.
55 + *
56 + * @return external interface name
57 + */
58 + public String gatewayExternalInterfaceName() {
59 + return this.get("gatewayExternalInterfaceName", "");
60 + }
61 +
62 + /**
63 + * Returns gateway's external interface mac.
64 + *
65 + * @return external interface mac
66 + */
67 + public String gatewayExternalInterfaceMac() {
68 + return this.get("gatewayExternalInterfaceMac", "");
69 + }
70 +}
...@@ -71,6 +71,7 @@ public class OpenstackRoutingRulePopulator { ...@@ -71,6 +71,7 @@ public class OpenstackRoutingRulePopulator {
71 private final OpenstackInterfaceService openstackService; 71 private final OpenstackInterfaceService openstackService;
72 private final DeviceService deviceService; 72 private final DeviceService deviceService;
73 private final DriverService driverService; 73 private final DriverService driverService;
74 + private final OpenstackRoutingConfig config;
74 75
75 private static final String PORTNAME_PREFIX_VM = "tap"; 76 private static final String PORTNAME_PREFIX_VM = "tap";
76 private static final String PORTNAME_PREFIX_ROUTER = "qr"; 77 private static final String PORTNAME_PREFIX_ROUTER = "qr";
...@@ -93,9 +94,6 @@ public class OpenstackRoutingRulePopulator { ...@@ -93,9 +94,6 @@ public class OpenstackRoutingRulePopulator {
93 private OpenstackRouter router; 94 private OpenstackRouter router;
94 private OpenstackRouterInterface routerInterface; 95 private OpenstackRouterInterface routerInterface;
95 96
96 - // TODO: This will be replaced to get the information from openstackswitchingservice.
97 - private static final String EXTERNAL_INTERFACE_NAME = "veth0";
98 -
99 /** 97 /**
100 * The constructor of openstackRoutingRulePopulator. 98 * The constructor of openstackRoutingRulePopulator.
101 * 99 *
...@@ -104,20 +102,23 @@ public class OpenstackRoutingRulePopulator { ...@@ -104,20 +102,23 @@ public class OpenstackRoutingRulePopulator {
104 * @param flowObjectiveService FlowObjectiveService 102 * @param flowObjectiveService FlowObjectiveService
105 * @param deviceService DeviceService 103 * @param deviceService DeviceService
106 * @param driverService DriverService 104 * @param driverService DriverService
105 + * @param config OpenstackRoutingConfig
107 */ 106 */
108 public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService, 107 public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService,
109 - FlowObjectiveService flowObjectiveService, 108 + FlowObjectiveService flowObjectiveService, DeviceService deviceService,
110 - DeviceService deviceService, DriverService driverService) { 109 + DriverService driverService, OpenstackRoutingConfig config) {
111 this.appId = appId; 110 this.appId = appId;
112 this.flowObjectiveService = flowObjectiveService; 111 this.flowObjectiveService = flowObjectiveService;
113 - this.openstackService = openstackService; 112 + this.openstackService = checkNotNull(openstackService);
114 this.deviceService = deviceService; 113 this.deviceService = deviceService;
115 this.driverService = driverService; 114 this.driverService = driverService;
115 + this.config = config;
116 } 116 }
117 117
118 /** 118 /**
119 * Populates flow rules for Pnat configurations. 119 * Populates flow rules for Pnat configurations.
120 - * @param inboundPacket Packet-in event packet 120 + *
121 + * @param inboundPacket Packet-in event packet
121 * @param openstackPort Target VM information 122 * @param openstackPort Target VM information
122 * @param portNum Pnat port number 123 * @param portNum Pnat port number
123 * @param externalIp external ip address 124 * @param externalIp external ip address
...@@ -168,6 +169,7 @@ public class OpenstackRoutingRulePopulator { ...@@ -168,6 +169,7 @@ public class OpenstackRoutingRulePopulator {
168 tBuilder.setUdpSrc(TpPort.tpPort(portNum)); 169 tBuilder.setUdpSrc(TpPort.tpPort(portNum));
169 break; 170 break;
170 default: 171 default:
172 + log.debug("Unsupported IPv4 protocol {}");
171 break; 173 break;
172 } 174 }
173 175
...@@ -188,7 +190,7 @@ public class OpenstackRoutingRulePopulator { ...@@ -188,7 +190,7 @@ public class OpenstackRoutingRulePopulator {
188 190
189 private Port getPortNumOfExternalInterface() { 191 private Port getPortNumOfExternalInterface() {
190 return deviceService.getPorts(inboundPacket.receivedFrom().deviceId()).stream() 192 return deviceService.getPorts(inboundPacket.receivedFrom().deviceId()).stream()
191 - .filter(p -> p.annotations().value(PORTNAME).equals(EXTERNAL_INTERFACE_NAME)) 193 + .filter(p -> p.annotations().value(PORTNAME).equals(config.gatewayExternalInterfaceName()))
192 .findAny().orElse(null); 194 .findAny().orElse(null);
193 } 195 }
194 196
...@@ -239,7 +241,15 @@ public class OpenstackRoutingRulePopulator { ...@@ -239,7 +241,15 @@ public class OpenstackRoutingRulePopulator {
239 flowObjectiveService.forward(inboundPacket.receivedFrom().deviceId(), fo); 241 flowObjectiveService.forward(inboundPacket.receivedFrom().deviceId(), fo);
240 } 242 }
241 243
242 - private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) { 244 + /**
245 + * Returns NiciraExtension treatment.
246 + *
247 + * @param id device id
248 + * @param hostIp host ip
249 + * @return NiciraExtension treatment
250 + */
251 +
252 + public ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) {
243 Driver driver = driverService.getDriver(id); 253 Driver driver = driverService.getDriver(id);
244 DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id)); 254 DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id));
245 ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class); 255 ExtensionTreatmentResolver resolver = driverHandler.behaviour(ExtensionTreatmentResolver.class);
...@@ -257,7 +267,13 @@ public class OpenstackRoutingRulePopulator { ...@@ -257,7 +267,13 @@ public class OpenstackRoutingRulePopulator {
257 return extensionInstruction; 267 return extensionInstruction;
258 } 268 }
259 269
260 - private PortNumber getTunnelPort(DeviceId deviceId) { 270 + /**
271 + * Returns port number of vxlan tunnel.
272 + *
273 + * @param deviceId device id
274 + * @return port number of vxlan tunnel
275 + */
276 + public PortNumber getTunnelPort(DeviceId deviceId) {
261 Port port = deviceService.getPorts(deviceId).stream() 277 Port port = deviceService.getPorts(deviceId).stream()
262 .filter(p -> p.annotations().value(PORTNAME).equals(PORTNAME_PREFIX_TUNNEL)) 278 .filter(p -> p.annotations().value(PORTNAME).equals(PORTNAME_PREFIX_TUNNEL))
263 .findAny().orElse(null); 279 .findAny().orElse(null);
...@@ -343,16 +359,11 @@ public class OpenstackRoutingRulePopulator { ...@@ -343,16 +359,11 @@ public class OpenstackRoutingRulePopulator {
343 } 359 }
344 360
345 private Device getGatewayNode() { 361 private Device getGatewayNode() {
346 - return checkNotNull(StreamSupport.stream(deviceService.getAvailableDevices().spliterator(), false) 362 + return checkNotNull(deviceService.getDevice(DeviceId.deviceId(config.gatewayBridgeId())));
347 - .filter(d -> checkGatewayNode(d.id()))
348 - .findAny()
349 - .orElse(null));
350 } 363 }
351 364
352 private boolean checkGatewayNode(DeviceId deviceId) { 365 private boolean checkGatewayNode(DeviceId deviceId) {
353 - return !deviceService.getPorts(deviceId).stream().anyMatch(port -> 366 + return deviceId.toString().equals(config.gatewayBridgeId());
354 - port.annotations().value(PORTNAME).startsWith(PORTNAME_PREFIX_ROUTER) ||
355 - port.annotations().value(PORTNAME).startsWith(PORTNAME_PREFIX_VM));
356 } 367 }
357 368
358 private long getVni(OpenstackPort openstackPort) { 369 private long getVni(OpenstackPort openstackPort) {
......
...@@ -94,6 +94,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -94,6 +94,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 94 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
95 protected DriverService driverService; 95 protected DriverService driverService;
96 96
97 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
97 protected OpenstackInterfaceService openstackService; 98 protected OpenstackInterfaceService openstackService;
98 99
99 public static final String PORTNAME_PREFIX_VM = "tap"; 100 public static final String PORTNAME_PREFIX_VM = "tap";
...@@ -126,6 +127,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -126,6 +127,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
126 packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1)); 127 packetService.addProcessor(internalPacketProcessor, PacketProcessor.director(1));
127 deviceService.addListener(internalDeviceListener); 128 deviceService.addListener(internalDeviceListener);
128 hostService.addListener(internalHostListener); 129 hostService.addListener(internalHostListener);
130 + arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService);
129 131
130 arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService); 132 arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService);
131 sgRulePopulator = new OpenstackSecurityGroupRulePopulator(appId, openstackService, flowObjectiveService); 133 sgRulePopulator = new OpenstackSecurityGroupRulePopulator(appId, openstackService, flowObjectiveService);
...@@ -204,10 +206,12 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -204,10 +206,12 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
204 206
205 @Override 207 @Override
206 public void createNetwork(OpenstackNetwork openstackNetwork) { 208 public void createNetwork(OpenstackNetwork openstackNetwork) {
209 + //TODO
207 } 210 }
208 211
209 @Override 212 @Override
210 public void createSubnet(OpenstackSubnet openstackSubnet) { 213 public void createSubnet(OpenstackSubnet openstackSubnet) {
214 + //TODO
211 } 215 }
212 216
213 @Override 217 @Override
...@@ -296,9 +300,17 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -296,9 +300,17 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
296 300
297 private void updatePortMap(DeviceId deviceId, String portName, Collection<OpenstackNetwork> networks, 301 private void updatePortMap(DeviceId deviceId, String portName, Collection<OpenstackNetwork> networks,
298 Collection<OpenstackSubnet> subnets, OpenstackPort openstackPort) { 302 Collection<OpenstackSubnet> subnets, OpenstackPort openstackPort) {
299 - long vni = Long.parseLong(networks.stream() 303 + long vni;
304 + OpenstackNetwork openstackNetwork = networks.stream()
300 .filter(n -> n.id().equals(openstackPort.networkId())) 305 .filter(n -> n.id().equals(openstackPort.networkId()))
301 - .findAny().orElse(null).segmentId()); 306 + .findAny().orElse(null);
307 + if (openstackNetwork != null) {
308 + vni = Long.parseLong(openstackNetwork.segmentId());
309 + } else {
310 + log.debug("updatePortMap failed because there's no OpenstackNetwork matches {}", openstackPort.networkId());
311 + return;
312 + }
313 +
302 314
303 OpenstackSubnet openstackSubnet = subnets.stream() 315 OpenstackSubnet openstackSubnet = subnets.stream()
304 .filter(n -> n.networkId().equals(openstackPort.networkId())) 316 .filter(n -> n.networkId().equals(openstackPort.networkId()))
...@@ -312,6 +324,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -312,6 +324,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
312 .setHostMac(openstackPort.macAddress()) 324 .setHostMac(openstackPort.macAddress())
313 .setVni(vni) 325 .setVni(vni)
314 .setGatewayIP(gatewayIPAddress) 326 .setGatewayIP(gatewayIPAddress)
327 + .setNetworkId(openstackPort.networkId())
315 .setSecurityGroups(openstackPort.securityGroups()); 328 .setSecurityGroups(openstackPort.securityGroups());
316 329
317 openstackPortInfoMap.put(portName, portBuilder.build()); 330 openstackPortInfoMap.put(portName, portBuilder.build());
...@@ -321,7 +334,6 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -321,7 +334,6 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
321 securityGroupMap.put(sgId, openstackService.getSecurityGroup(sgId)); 334 securityGroupMap.put(sgId, openstackService.getSecurityGroup(sgId));
322 } 335 }
323 }); 336 });
324 -
325 } 337 }
326 338
327 private void processHostRemoved(Host host) { 339 private void processHostRemoved(Host host) {
...@@ -440,6 +452,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -440,6 +452,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
440 processPortRemoved((Device) deviceEvent.subject(), deviceEvent.port()); 452 processPortRemoved((Device) deviceEvent.subject(), deviceEvent.port());
441 break; 453 break;
442 default: 454 default:
455 + log.debug("Unsupported deviceEvent type {}", deviceEvent.type().toString());
443 break; 456 break;
444 } 457 }
445 } else if (event instanceof HostEvent) { 458 } else if (event instanceof HostEvent) {
...@@ -450,6 +463,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { ...@@ -450,6 +463,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService {
450 processHostRemoved((Host) hostEvent.subject()); 463 processHostRemoved((Host) hostEvent.subject());
451 break; 464 break;
452 default: 465 default:
466 + log.debug("Unsupported hostEvent type {}", hostEvent.type().toString());
453 break; 467 break;
454 } 468 }
455 } 469 }
......