Committed by
Gerrit Code Review
Refactored OpenstackSwitching app
[DONE] - Restructured to activate or deactivate switching and routing app separately - Fixed to add or remove host when port is detected or vanished - Use openstack node service to get integration bridges and data IP [TODO] - Remove use of OpenstackPortInfo - Support installing flow rules for exising VMs - Call security group update method when port update triggered from OpenStack Change-Id: Ic0b2ac3f7ab07f0e20c97c6edfdd1928b9767baf
Showing
39 changed files
with
481 additions
and
464 deletions
... | @@ -117,8 +117,8 @@ APPS = [ | ... | @@ -117,8 +117,8 @@ APPS = [ |
117 | '//apps/mlb:onos-apps-mlb-oar', | 117 | '//apps/mlb:onos-apps-mlb-oar', |
118 | '//apps/openstackinterface:onos-apps-openstackinterface-oar', | 118 | '//apps/openstackinterface:onos-apps-openstackinterface-oar', |
119 | '//apps/openstacknetworking:onos-apps-openstacknetworking-oar', | 119 | '//apps/openstacknetworking:onos-apps-openstacknetworking-oar', |
120 | - '//apps/openstacknetworking/openstackrouting:onos-apps-openstacknetworking-openstackrouting-oar', | 120 | + '//apps/openstacknetworking/routing:onos-apps-openstacknetworking-routing-oar', |
121 | - '//apps/openstacknetworking/openstackswitching:onos-apps-openstacknetworking-openstackswitching-oar', | 121 | + '//apps/openstacknetworking/switching:onos-apps-openstacknetworking-switching-oar', |
122 | '//apps/mobility:onos-apps-mobility-oar', | 122 | '//apps/mobility:onos-apps-mobility-oar', |
123 | '//apps/optical:onos-apps-optical-oar', | 123 | '//apps/optical:onos-apps-optical-oar', |
124 | '//apps/newoptical:onos-apps-newoptical-oar', | 124 | '//apps/newoptical:onos-apps-newoptical-oar', | ... | ... |
... | @@ -8,5 +8,5 @@ onos_app ( | ... | @@ -8,5 +8,5 @@ onos_app ( |
8 | category = 'Utility', | 8 | category = 'Utility', |
9 | url = 'http://onosproject.org', | 9 | url = 'http://onosproject.org', |
10 | included_bundles = BUNDLES, | 10 | included_bundles = BUNDLES, |
11 | - required_apps = [ 'org.onosproject.openstackinterface' ], | 11 | + required_apps = [ 'org.onosproject.openstackrouting', 'org.onosproject.openstackswitching' ] |
12 | ) | 12 | ) | ... | ... |
... | @@ -19,14 +19,12 @@ import org.onlab.packet.Ip4Address; | ... | @@ -19,14 +19,12 @@ import org.onlab.packet.Ip4Address; |
19 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | 21 | ||
22 | -import java.util.Collection; | ||
23 | -import java.util.Collections; | ||
24 | - | ||
25 | import static com.google.common.base.Preconditions.checkNotNull; | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
26 | 23 | ||
27 | /** | 24 | /** |
28 | * Contains OpenstackPort Information. | 25 | * Contains OpenstackPort Information. |
29 | */ | 26 | */ |
27 | +// TODO remove this | ||
30 | public final class OpenstackPortInfo { | 28 | public final class OpenstackPortInfo { |
31 | private final Ip4Address hostIp; | 29 | private final Ip4Address hostIp; |
32 | private final MacAddress hostMac; | 30 | private final MacAddress hostMac; |
... | @@ -34,7 +32,6 @@ public final class OpenstackPortInfo { | ... | @@ -34,7 +32,6 @@ public final class OpenstackPortInfo { |
34 | private final long vni; | 32 | private final long vni; |
35 | private final Ip4Address gatewayIP; | 33 | private final Ip4Address gatewayIP; |
36 | private final String networkId; | 34 | private final String networkId; |
37 | - private final Collection<String> securityGroups; | ||
38 | 35 | ||
39 | /** | 36 | /** |
40 | * Returns OpenstackPortInfo reference. | 37 | * Returns OpenstackPortInfo reference. |
... | @@ -45,17 +42,15 @@ public final class OpenstackPortInfo { | ... | @@ -45,17 +42,15 @@ public final class OpenstackPortInfo { |
45 | * @param vni tunnel ID | 42 | * @param vni tunnel ID |
46 | * @param gatewayIP gateway IP address | 43 | * @param gatewayIP gateway IP address |
47 | * @param networkId network identifier | 44 | * @param networkId network identifier |
48 | - * @param securityGroups security group list | ||
49 | */ | 45 | */ |
50 | public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni, | 46 | public OpenstackPortInfo(Ip4Address hostIp, MacAddress hostMac, DeviceId deviceId, long vni, |
51 | - Ip4Address gatewayIP, String networkId, Collection<String> securityGroups) { | 47 | + Ip4Address gatewayIP, String networkId) { |
52 | this.hostIp = hostIp; | 48 | this.hostIp = hostIp; |
53 | this.hostMac = hostMac; | 49 | this.hostMac = hostMac; |
54 | this.deviceId = deviceId; | 50 | this.deviceId = deviceId; |
55 | this.vni = vni; | 51 | this.vni = vni; |
56 | this.gatewayIP = gatewayIP; | 52 | this.gatewayIP = gatewayIP; |
57 | this.networkId = networkId; | 53 | this.networkId = networkId; |
58 | - this.securityGroups = securityGroups; | ||
59 | } | 54 | } |
60 | 55 | ||
61 | /** | 56 | /** |
... | @@ -113,15 +108,6 @@ public final class OpenstackPortInfo { | ... | @@ -113,15 +108,6 @@ public final class OpenstackPortInfo { |
113 | } | 108 | } |
114 | 109 | ||
115 | /** | 110 | /** |
116 | - * Returns Security Group ID list. | ||
117 | - * | ||
118 | - * @return list of Security Group ID | ||
119 | - */ | ||
120 | - public Collection<String> securityGroups() { | ||
121 | - return Collections.unmodifiableCollection(securityGroups); | ||
122 | - } | ||
123 | - | ||
124 | - /** | ||
125 | * Returns the builder of the OpenstackPortInfo. | 111 | * Returns the builder of the OpenstackPortInfo. |
126 | * | 112 | * |
127 | * @return OpenstackPortInfo builder reference | 113 | * @return OpenstackPortInfo builder reference |
... | @@ -140,7 +126,6 @@ public final class OpenstackPortInfo { | ... | @@ -140,7 +126,6 @@ public final class OpenstackPortInfo { |
140 | private DeviceId deviceId; | 126 | private DeviceId deviceId; |
141 | private long vni; | 127 | private long vni; |
142 | private Ip4Address gatewayIP; | 128 | private Ip4Address gatewayIP; |
143 | - private Collection<String> securityGroups; | ||
144 | private String networkId; | 129 | private String networkId; |
145 | 130 | ||
146 | /** | 131 | /** |
... | @@ -210,23 +195,12 @@ public final class OpenstackPortInfo { | ... | @@ -210,23 +195,12 @@ public final class OpenstackPortInfo { |
210 | } | 195 | } |
211 | 196 | ||
212 | /** | 197 | /** |
213 | - * Sets the security group ID list. | ||
214 | - * | ||
215 | - * @param securityGroups security group ID list | ||
216 | - * @return Builder reference | ||
217 | - */ | ||
218 | - public Builder setSecurityGroups(Collection<String> securityGroups) { | ||
219 | - this.securityGroups = securityGroups; | ||
220 | - return this; | ||
221 | - } | ||
222 | - | ||
223 | - /** | ||
224 | * Builds the OpenstackPortInfo reference. | 198 | * Builds the OpenstackPortInfo reference. |
225 | * | 199 | * |
226 | * @return OpenstackPortInfo reference | 200 | * @return OpenstackPortInfo reference |
227 | */ | 201 | */ |
228 | public OpenstackPortInfo build() { | 202 | public OpenstackPortInfo build() { |
229 | - return new OpenstackPortInfo(hostIp, hostMac, deviceId, vni, gatewayIP, networkId, securityGroups); | 203 | + return new OpenstackPortInfo(hostIp, hostMac, deviceId, vni, gatewayIP, networkId); |
230 | } | 204 | } |
231 | } | 205 | } |
232 | } | 206 | } | ... | ... |
... | @@ -15,57 +15,19 @@ | ... | @@ -15,57 +15,19 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking; | 16 | package org.onosproject.openstacknetworking; |
17 | 17 | ||
18 | -import org.onosproject.openstackinterface.OpenstackNetwork; | ||
19 | -import org.onosproject.openstackinterface.OpenstackPort; | ||
20 | -import org.onosproject.openstackinterface.OpenstackSubnet; | ||
21 | - | ||
22 | import java.util.Map; | 18 | import java.util.Map; |
23 | 19 | ||
24 | /** | 20 | /** |
25 | * Handles port management REST API from Openstack for VMs. | 21 | * Handles port management REST API from Openstack for VMs. |
26 | */ | 22 | */ |
23 | +// TODO remove this | ||
27 | public interface OpenstackSwitchingService { | 24 | public interface OpenstackSwitchingService { |
28 | 25 | ||
29 | /** | 26 | /** |
30 | - * Store the port information created by Openstack. | ||
31 | - * | ||
32 | - * @param openstackPort port information | ||
33 | - */ | ||
34 | - void createPorts(OpenstackPort openstackPort); | ||
35 | - | ||
36 | - /** | ||
37 | - * Removes flow rules corresponding to the port removed by Openstack. | ||
38 | - * | ||
39 | - * @param uuid UUID | ||
40 | - */ | ||
41 | - void removePort(String uuid); | ||
42 | - | ||
43 | - /** | ||
44 | - * Updates flow rules corresponding to the port information updated by Openstack. | ||
45 | - * | ||
46 | - * @param openstackPort OpenStack port | ||
47 | - */ | ||
48 | - void updatePort(OpenstackPort openstackPort); | ||
49 | - | ||
50 | - /** | ||
51 | - * Stores the network information created by openstack. | ||
52 | - * | ||
53 | - * @param openstackNetwork network information | ||
54 | - */ | ||
55 | - void createNetwork(OpenstackNetwork openstackNetwork); | ||
56 | - | ||
57 | - /** | ||
58 | - * Stores the subnet information created by openstack. | ||
59 | - * | ||
60 | - * @param openstackSubnet subnet information | ||
61 | - */ | ||
62 | - void createSubnet(OpenstackSubnet openstackSubnet); | ||
63 | - | ||
64 | - /** | ||
65 | * Retruns OpenstackPortInfo map. | 27 | * Retruns OpenstackPortInfo map. |
66 | * | 28 | * |
67 | * @return OpenstackPortInfo map | 29 | * @return OpenstackPortInfo map |
68 | */ | 30 | */ |
31 | + // TODO remove this | ||
69 | Map<String, OpenstackPortInfo> openstackPortInfo(); | 32 | Map<String, OpenstackPortInfo> openstackPortInfo(); |
70 | - | ||
71 | } | 33 | } | ... | ... |
apps/openstacknetworking/app/app.xml
deleted
100644 → 0
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!-- | ||
3 | - ~ Copyright 2016-present Open Networking Laboratory | ||
4 | - ~ | ||
5 | - ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | - ~ you may not use this file except in compliance with the License. | ||
7 | - ~ You may obtain a copy of the License at | ||
8 | - ~ | ||
9 | - ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | - ~ | ||
11 | - ~ Unless required by applicable law or agreed to in writing, software | ||
12 | - ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | - ~ See the License for the specific language governing permissions and | ||
15 | - ~ limitations under the License. | ||
16 | - --> | ||
17 | -<app name="org.onosproject.openstacknetworking" origin="ON.Lab" version="${project.version}" | ||
18 | - category="Utility" url="http://onosproject.org" title="OpenStack Networking App" | ||
19 | - featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | ||
20 | - features="${project.artifactId}" | ||
21 | - apps="org.onosproject.openstackswitching,org.onosproject.openstackrouting"> | ||
22 | - <description>${project.description}</description> | ||
23 | - <artifact>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</artifact> | ||
24 | - <artifact>mvn:${project.groupId}/onos-app-openstacknetworking-web/${project.version}</artifact> | ||
25 | -</app> |
apps/openstacknetworking/app/pom.xml
deleted
100644 → 0
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!-- | ||
3 | - ~ Copyright 2016-present Open Networking Laboratory | ||
4 | - ~ | ||
5 | - ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | - ~ you may not use this file except in compliance with the License. | ||
7 | - ~ You may obtain a copy of the License at | ||
8 | - ~ | ||
9 | - ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | - ~ | ||
11 | - ~ Unless required by applicable law or agreed to in writing, software | ||
12 | - ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | - ~ See the License for the specific language governing permissions and | ||
15 | - ~ limitations under the License. | ||
16 | - --> | ||
17 | -<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
18 | - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
19 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
20 | - <modelVersion>4.0.0</modelVersion> | ||
21 | - | ||
22 | - <parent> | ||
23 | - <groupId>org.onosproject</groupId> | ||
24 | - <artifactId>onos-app-openstacknetworking</artifactId> | ||
25 | - <version>1.7.0-SNAPSHOT</version> | ||
26 | - </parent> | ||
27 | - | ||
28 | - <artifactId>onos-app-openstacknetworking-app</artifactId> | ||
29 | - <packaging>pom</packaging> | ||
30 | - | ||
31 | - <properties> | ||
32 | - <onos.app.readme>Openstack Networking Application.</onos.app.readme> | ||
33 | - </properties> | ||
34 | - | ||
35 | - <description>SONA Openstack Networking main Application</description> | ||
36 | - | ||
37 | - <dependencies> | ||
38 | - <dependency> | ||
39 | - <groupId>org.onosproject</groupId> | ||
40 | - <artifactId>onos-app-openstackswitching</artifactId> | ||
41 | - <version>${project.version}</version> | ||
42 | - </dependency> | ||
43 | - <dependency> | ||
44 | - <groupId>org.onosproject</groupId> | ||
45 | - <artifactId>onos-app-openstackrouting</artifactId> | ||
46 | - <version>${project.version}</version> | ||
47 | - </dependency> | ||
48 | - <dependency> | ||
49 | - <groupId>org.onosproject</groupId> | ||
50 | - <artifactId>onos-app-openstacknetworking-api</artifactId> | ||
51 | - <version>${project.version}</version> | ||
52 | - </dependency> | ||
53 | - <dependency> | ||
54 | - <groupId>org.onosproject</groupId> | ||
55 | - <artifactId>onos-app-openstacknetworking-web</artifactId> | ||
56 | - <version>${project.version}</version> | ||
57 | - </dependency> | ||
58 | - </dependencies> | ||
59 | -</project> |
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!-- | ||
3 | - ~ Copyright 2016-present Open Networking Laboratory | ||
4 | - ~ | ||
5 | - ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | - ~ you may not use this file except in compliance with the License. | ||
7 | - ~ You may obtain a copy of the License at | ||
8 | - ~ | ||
9 | - ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | - ~ | ||
11 | - ~ Unless required by applicable law or agreed to in writing, software | ||
12 | - ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | - ~ See the License for the specific language governing permissions and | ||
15 | - ~ limitations under the License. | ||
16 | - --> | ||
17 | -<app name="org.onosproject.openstackrouting" origin="ON.Lab" version="${project.version}" | ||
18 | - category="default" url="http://onosproject.org" | ||
19 | - featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | ||
20 | - features="${project.artifactId}" > | ||
21 | - <description>${project.description}</description> | ||
22 | - <artifact>mvn:${project.groupId}/onos-app-openstackrouting/${project.version}</artifact> | ||
23 | - <artifact>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</artifact> | ||
24 | -</app> |
1 | -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | -<!-- | ||
3 | - ~ Copyright 2016-present Open Networking Laboratory | ||
4 | - ~ | ||
5 | - ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | - ~ you may not use this file except in compliance with the License. | ||
7 | - ~ You may obtain a copy of the License at | ||
8 | - ~ | ||
9 | - ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | - ~ | ||
11 | - ~ Unless required by applicable law or agreed to in writing, software | ||
12 | - ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | - ~ See the License for the specific language governing permissions and | ||
15 | - ~ limitations under the License. | ||
16 | - --> | ||
17 | -<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
18 | - <feature name="${project.artifactId}" version="${project.version}" | ||
19 | - description="${project.description}"> | ||
20 | - <feature>onos-api</feature> | ||
21 | - <bundle>mvn:${project.groupId}/onos-app-openstackrouting/${project.version}</bundle> | ||
22 | - <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</bundle> | ||
23 | - </feature> | ||
24 | -</features> |
1 | -<?xml version="1.0" encoding="UTF-8"?> | ||
2 | -<!-- | ||
3 | - ~ Copyright 2016-present Open Networking Laboratory | ||
4 | - ~ | ||
5 | - ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | - ~ you may not use this file except in compliance with the License. | ||
7 | - ~ You may obtain a copy of the License at | ||
8 | - ~ | ||
9 | - ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
10 | - ~ | ||
11 | - ~ Unless required by applicable law or agreed to in writing, software | ||
12 | - ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
13 | - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | - ~ See the License for the specific language governing permissions and | ||
15 | - ~ limitations under the License. | ||
16 | - --> | ||
17 | -<app name="org.onosproject.openstackswitching" origin="ON.Lab" version="${project.version}" | ||
18 | - category="default" url="http://onosproject.org" | ||
19 | - featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | ||
20 | - features="${project.artifactId}" | ||
21 | - apps="org.onosproject.dhcp"> | ||
22 | - <description>${project.description}</description> | ||
23 | - <artifact>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</artifact> | ||
24 | - <artifact>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</artifact> | ||
25 | -</app> |
1 | -/* | ||
2 | -* Copyright 2016-present Open Networking Laboratory | ||
3 | -* | ||
4 | -* Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | -* you may not use this file except in compliance with the License. | ||
6 | -* You may obtain a copy of the License at | ||
7 | -* | ||
8 | -* http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | -* | ||
10 | -* Unless required by applicable law or agreed to in writing, software | ||
11 | -* distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | -* See the License for the specific language governing permissions and | ||
14 | -* limitations under the License. | ||
15 | -*/ | ||
16 | -package org.onosproject.openstacknetworking.switching; | ||
17 | - | ||
18 | -import org.onlab.packet.ARP; | ||
19 | -import org.onlab.packet.Ethernet; | ||
20 | -import org.onlab.packet.Ip4Address; | ||
21 | -import org.onlab.packet.IpAddress; | ||
22 | -import org.onlab.packet.MacAddress; | ||
23 | -import org.onosproject.net.Host; | ||
24 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
25 | -import org.onosproject.net.flow.TrafficTreatment; | ||
26 | -import org.onosproject.net.host.HostService; | ||
27 | -import org.onosproject.net.packet.DefaultOutboundPacket; | ||
28 | -import org.onosproject.net.packet.InboundPacket; | ||
29 | -import org.onosproject.net.packet.PacketService; | ||
30 | -import org.onosproject.openstackinterface.OpenstackInterfaceService; | ||
31 | -import org.onosproject.openstackinterface.OpenstackPort; | ||
32 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
33 | -import org.slf4j.Logger; | ||
34 | -import org.slf4j.LoggerFactory; | ||
35 | -import java.nio.ByteBuffer; | ||
36 | -import java.util.Collection; | ||
37 | - | ||
38 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
39 | - | ||
40 | -/** | ||
41 | - * Handles ARP packet from VMs. | ||
42 | - */ | ||
43 | -public class OpenstackArpHandler { | ||
44 | - | ||
45 | - private static Logger log = LoggerFactory | ||
46 | - .getLogger(OpenstackArpHandler.class); | ||
47 | - private static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f"); | ||
48 | - private PacketService packetService; | ||
49 | - private OpenstackInterfaceService openstackService; | ||
50 | - private HostService hostService; | ||
51 | - | ||
52 | - /** | ||
53 | - * Returns OpenstackArpHandler reference. | ||
54 | - * | ||
55 | - * @param openstackService OpenstackNetworkingService reference | ||
56 | - * @param packetService PacketService reference | ||
57 | - * @param hostService host service | ||
58 | - */ | ||
59 | - public OpenstackArpHandler(OpenstackInterfaceService openstackService, PacketService packetService, | ||
60 | - HostService hostService) { | ||
61 | - this.openstackService = openstackService; | ||
62 | - this.packetService = packetService; | ||
63 | - this.hostService = hostService; | ||
64 | - } | ||
65 | - | ||
66 | - /** | ||
67 | - * Processes ARP request packets. | ||
68 | - * It checks if the target IP is owned by a known host first and then ask to | ||
69 | - * OpenStack if it's not. This ARP proxy does not support overlapping IP. | ||
70 | - * | ||
71 | - * @param pkt ARP request packet | ||
72 | - * @param openstackPortInfoCollection collection of port information | ||
73 | - */ | ||
74 | - public void processPacketIn(InboundPacket pkt, Collection<OpenstackPortInfo> openstackPortInfoCollection) { | ||
75 | - Ethernet ethRequest = pkt.parsed(); | ||
76 | - ARP arp = (ARP) ethRequest.getPayload(); | ||
77 | - | ||
78 | - if (arp.getOpCode() != ARP.OP_REQUEST) { | ||
79 | - return; | ||
80 | - } | ||
81 | - | ||
82 | - IpAddress sourceIp = Ip4Address.valueOf(arp.getSenderProtocolAddress()); | ||
83 | - MacAddress srcMac = MacAddress.valueOf(arp.getSenderHardwareAddress()); | ||
84 | - OpenstackPortInfo portInfo = openstackPortInfoCollection.stream() | ||
85 | - .filter(p -> p.ip().equals(sourceIp) && p.mac().equals(srcMac)).findFirst().orElse(null); | ||
86 | - IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress()); | ||
87 | - | ||
88 | - MacAddress dstMac; | ||
89 | - | ||
90 | - if (targetIp.equals(portInfo == null ? null : portInfo.gatewayIP())) { | ||
91 | - dstMac = GATEWAY_MAC; | ||
92 | - } else { | ||
93 | - dstMac = getMacFromHostService(targetIp); | ||
94 | - if (dstMac == null) { | ||
95 | - dstMac = getMacFromOpenstack(targetIp); | ||
96 | - } | ||
97 | - } | ||
98 | - | ||
99 | - if (dstMac == null) { | ||
100 | - log.debug("Failed to find MAC address for {}", targetIp.toString()); | ||
101 | - return; | ||
102 | - } | ||
103 | - | ||
104 | - Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), | ||
105 | - dstMac, | ||
106 | - ethRequest); | ||
107 | - | ||
108 | - TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
109 | - .setOutput(pkt.receivedFrom().port()) | ||
110 | - .build(); | ||
111 | - | ||
112 | - packetService.emit(new DefaultOutboundPacket( | ||
113 | - pkt.receivedFrom().deviceId(), | ||
114 | - treatment, | ||
115 | - ByteBuffer.wrap(ethReply.serialize()))); | ||
116 | - } | ||
117 | - | ||
118 | - /** | ||
119 | - * Returns MAC address of a host with a given target IP address by asking to | ||
120 | - * OpenStack. It does not support overlapping IP. | ||
121 | - * | ||
122 | - * @param targetIp target ip address | ||
123 | - * @return mac address, or null if it fails to fetch the mac | ||
124 | - */ | ||
125 | - private MacAddress getMacFromOpenstack(IpAddress targetIp) { | ||
126 | - checkNotNull(targetIp); | ||
127 | - | ||
128 | - OpenstackPort openstackPort = openstackService.ports() | ||
129 | - .stream() | ||
130 | - .filter(port -> port.fixedIps().containsValue(targetIp)) | ||
131 | - .findFirst() | ||
132 | - .orElse(null); | ||
133 | - | ||
134 | - if (openstackPort != null) { | ||
135 | - log.debug("Found MAC from OpenStack for {}", targetIp.toString()); | ||
136 | - return openstackPort.macAddress(); | ||
137 | - } else { | ||
138 | - return null; | ||
139 | - } | ||
140 | - } | ||
141 | - | ||
142 | - /** | ||
143 | - * Returns MAC address of a host with a given target IP address by asking to | ||
144 | - * host service. It does not support overlapping IP. | ||
145 | - * | ||
146 | - * @param targetIp target ip | ||
147 | - * @return mac address, or null if it fails to find the mac | ||
148 | - */ | ||
149 | - private MacAddress getMacFromHostService(IpAddress targetIp) { | ||
150 | - checkNotNull(targetIp); | ||
151 | - | ||
152 | - Host host = hostService.getHostsByIp(targetIp) | ||
153 | - .stream() | ||
154 | - .findFirst() | ||
155 | - .orElse(null); | ||
156 | - | ||
157 | - if (host != null) { | ||
158 | - log.debug("Found MAC from host service for {}", targetIp.toString()); | ||
159 | - return host.mac(); | ||
160 | - } else { | ||
161 | - return null; | ||
162 | - } | ||
163 | - } | ||
164 | -} |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
... | @@ -29,11 +29,10 @@ | ... | @@ -29,11 +29,10 @@ |
29 | <packaging>pom</packaging> | 29 | <packaging>pom</packaging> |
30 | 30 | ||
31 | <modules> | 31 | <modules> |
32 | - <module>app</module> | ||
33 | - <module>web</module> | ||
34 | <module>api</module> | 32 | <module>api</module> |
35 | - <module>openstackswitching</module> | 33 | + <module>web</module> |
36 | - <module>openstackrouting</module> | 34 | + <module>switching</module> |
35 | + <module>routing</module> | ||
37 | </modules> | 36 | </modules> |
38 | 37 | ||
39 | <description>SONA Openstack Networking Application</description> | 38 | <description>SONA Openstack Networking Application</description> | ... | ... |
... | @@ -4,12 +4,13 @@ COMPILE_DEPS = [ | ... | @@ -4,12 +4,13 @@ COMPILE_DEPS = [ |
4 | '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | 4 | '//apps/openstackinterface/api:onos-apps-openstackinterface-api', |
5 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', | 5 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', |
6 | '//apps/scalablegateway:onos-apps-scalablegateway', | 6 | '//apps/scalablegateway:onos-apps-scalablegateway', |
7 | + '//apps/openstacknode:onos-apps-openstacknode', | ||
7 | ] | 8 | ] |
8 | 9 | ||
9 | BUNDLES = [ | 10 | BUNDLES = [ |
10 | - '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | ||
11 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', | 11 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', |
12 | - '//apps/openstacknetworking/openstackrouting:onos-apps-openstacknetworking-openstackrouting', | 12 | + '//apps/openstacknetworking/web:onos-apps-openstacknetworking-web', |
13 | + '//apps/openstacknetworking/routing:onos-apps-openstacknetworking-routing', | ||
13 | ] | 14 | ] |
14 | 15 | ||
15 | osgi_jar_with_tests ( | 16 | osgi_jar_with_tests ( |
... | @@ -17,9 +18,11 @@ osgi_jar_with_tests ( | ... | @@ -17,9 +18,11 @@ osgi_jar_with_tests ( |
17 | ) | 18 | ) |
18 | 19 | ||
19 | onos_app ( | 20 | onos_app ( |
21 | + app_name = 'org.onosproject.openstackrouting', | ||
20 | title = 'OpenStack Routing App', | 22 | title = 'OpenStack Routing App', |
21 | category = 'Utility', | 23 | category = 'Utility', |
22 | url = 'http://onosproject.org', | 24 | url = 'http://onosproject.org', |
23 | description = 'OpenStack routing application.', | 25 | description = 'OpenStack routing application.', |
24 | included_bundles = BUNDLES, | 26 | included_bundles = BUNDLES, |
27 | + required_apps = [ 'org.onosproject.openstackinterface', 'org.onosproject.openstacknode', 'org.onosproject.scalablegateway' ] | ||
25 | ) | 28 | ) | ... | ... |
... | @@ -20,5 +20,6 @@ | ... | @@ -20,5 +20,6 @@ |
20 | <feature>onos-api</feature> | 20 | <feature>onos-api</feature> |
21 | <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</bundle> | 21 | <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</bundle> |
22 | <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-web/${project.version}</bundle> | 22 | <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-web/${project.version}</bundle> |
23 | + <bundle>mvn:${project.groupId}/onos-app-openstackrouting/${project.version}</bundle> | ||
23 | </feature> | 24 | </feature> |
24 | </features> | 25 | </features> | ... | ... |
... | @@ -28,6 +28,17 @@ | ... | @@ -28,6 +28,17 @@ |
28 | <artifactId>onos-app-openstackrouting</artifactId> | 28 | <artifactId>onos-app-openstackrouting</artifactId> |
29 | <packaging>bundle</packaging> | 29 | <packaging>bundle</packaging> |
30 | 30 | ||
31 | + <properties> | ||
32 | + <onos.app.name>org.onosproject.openstackrouting</onos.app.name> | ||
33 | + <onos.app.title>Openstack Switching App</onos.app.title> | ||
34 | + <onos.app.category>Traffic Steering</onos.app.category> | ||
35 | + <onos.app.url>http://onosproject.org</onos.app.url> | ||
36 | + <onos.app.requires> | ||
37 | + org.onosproject.openstackinterface, | ||
38 | + org.onosproject.openstacknode | ||
39 | + </onos.app.requires> | ||
40 | + </properties> | ||
41 | + | ||
31 | <dependencies> | 42 | <dependencies> |
32 | <dependency> | 43 | <dependency> |
33 | <groupId>org.osgi</groupId> | 44 | <groupId>org.osgi</groupId> | ... | ... |
... | @@ -3,14 +3,14 @@ COMPILE_DEPS = [ | ... | @@ -3,14 +3,14 @@ COMPILE_DEPS = [ |
3 | '//core/store/serializers:onos-core-serializers', | 3 | '//core/store/serializers:onos-core-serializers', |
4 | '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | 4 | '//apps/openstackinterface/api:onos-apps-openstackinterface-api', |
5 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', | 5 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', |
6 | + '//apps/openstacknode:onos-apps-openstacknode', | ||
6 | '//apps/dhcp/api:onos-apps-dhcp-api', | 7 | '//apps/dhcp/api:onos-apps-dhcp-api', |
7 | ] | 8 | ] |
8 | 9 | ||
9 | BUNDLES = [ | 10 | BUNDLES = [ |
10 | - '//apps/openstackinterface/api:onos-apps-openstackinterface-api', | ||
11 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', | 11 | '//apps/openstacknetworking/api:onos-apps-openstacknetworking-api', |
12 | - '//apps/openstacknetworking/openstackswitching:onos-apps-openstacknetworking-openstackswitching', | 12 | + '//apps/openstacknetworking/web:onos-apps-openstacknetworking-web', |
13 | - '//apps/dhcp/api:onos-apps-dhcp-api', | 13 | + '//apps/openstacknetworking/switching:onos-apps-openstacknetworking-switching', |
14 | ] | 14 | ] |
15 | 15 | ||
16 | osgi_jar_with_tests ( | 16 | osgi_jar_with_tests ( |
... | @@ -18,9 +18,11 @@ osgi_jar_with_tests ( | ... | @@ -18,9 +18,11 @@ osgi_jar_with_tests ( |
18 | ) | 18 | ) |
19 | 19 | ||
20 | onos_app ( | 20 | onos_app ( |
21 | + app_name = 'org.onosproject.openstackswitching', | ||
21 | title = 'OpenStack Switching App', | 22 | title = 'OpenStack Switching App', |
22 | category = 'Utility', | 23 | category = 'Utility', |
23 | url = 'http://onosproject.org', | 24 | url = 'http://onosproject.org', |
24 | description = 'OpenStack Switching application.', | 25 | description = 'OpenStack Switching application.', |
25 | included_bundles = BUNDLES, | 26 | included_bundles = BUNDLES, |
27 | + required_apps = [ 'org.onosproject.openstackinterface', 'org.onosproject.openstacknode', 'org.onosproject.dhcp' ] | ||
26 | ) | 28 | ) | ... | ... |
... | @@ -19,6 +19,7 @@ | ... | @@ -19,6 +19,7 @@ |
19 | description="${project.description}"> | 19 | description="${project.description}"> |
20 | <feature>onos-api</feature> | 20 | <feature>onos-api</feature> |
21 | <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</bundle> | 21 | <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-api/${project.version}</bundle> |
22 | + <bundle>mvn:${project.groupId}/onos-app-openstacknetworking-web/${project.version}</bundle> | ||
22 | <bundle>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</bundle> | 23 | <bundle>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</bundle> |
23 | </feature> | 24 | </feature> |
24 | </features> | 25 | </features> | ... | ... |
... | @@ -28,8 +28,24 @@ | ... | @@ -28,8 +28,24 @@ |
28 | <artifactId>onos-app-openstackswitching</artifactId> | 28 | <artifactId>onos-app-openstackswitching</artifactId> |
29 | <packaging>bundle</packaging> | 29 | <packaging>bundle</packaging> |
30 | 30 | ||
31 | + <properties> | ||
32 | + <onos.app.name>org.onosproject.openstackswitching</onos.app.name> | ||
33 | + <onos.app.title>Openstack Switching App</onos.app.title> | ||
34 | + <onos.app.category>Traffic Steering</onos.app.category> | ||
35 | + <onos.app.url>http://onosproject.org</onos.app.url> | ||
36 | + <onos.app.requires> | ||
37 | + org.onosproject.dhcp, | ||
38 | + org.onosproject.openstackinterface, | ||
39 | + org.onosproject.openstacknode | ||
40 | + </onos.app.requires> | ||
41 | + </properties> | ||
42 | + | ||
31 | <dependencies> | 43 | <dependencies> |
32 | <dependency> | 44 | <dependency> |
45 | + <groupId>org.osgi</groupId> | ||
46 | + <artifactId>org.osgi.compendium</artifactId> | ||
47 | + </dependency> | ||
48 | + <dependency> | ||
33 | <groupId>org.onosproject</groupId> | 49 | <groupId>org.onosproject</groupId> |
34 | <artifactId>onos-app-openstacknetworking-api</artifactId> | 50 | <artifactId>onos-app-openstacknetworking-api</artifactId> |
35 | <version>${project.version}</version> | 51 | <version>${project.version}</version> |
... | @@ -41,6 +57,11 @@ | ... | @@ -41,6 +57,11 @@ |
41 | </dependency> | 57 | </dependency> |
42 | <dependency> | 58 | <dependency> |
43 | <groupId>org.onosproject</groupId> | 59 | <groupId>org.onosproject</groupId> |
60 | + <artifactId>onos-app-openstacknode</artifactId> | ||
61 | + <version>${project.version}</version> | ||
62 | + </dependency> | ||
63 | + <dependency> | ||
64 | + <groupId>org.onosproject</groupId> | ||
44 | <artifactId>onos-app-dhcp</artifactId> | 65 | <artifactId>onos-app-dhcp</artifactId> |
45 | <version>${project.version}</version> | 66 | <version>${project.version}</version> |
46 | </dependency> | 67 | </dependency> | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.openstacknetworking.switching; | ||
17 | + | ||
18 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
19 | +import org.onlab.osgi.ServiceDirectory; | ||
20 | +import org.onlab.packet.Ip4Address; | ||
21 | +import org.onlab.util.Tools; | ||
22 | +import org.onosproject.core.ApplicationId; | ||
23 | +import org.onosproject.core.CoreService; | ||
24 | +import org.onosproject.mastership.MastershipService; | ||
25 | +import org.onosproject.net.Host; | ||
26 | +import org.onosproject.net.host.HostEvent; | ||
27 | +import org.onosproject.net.host.HostListener; | ||
28 | +import org.onosproject.net.host.HostService; | ||
29 | +import org.slf4j.Logger; | ||
30 | + | ||
31 | +import java.util.Objects; | ||
32 | +import java.util.Optional; | ||
33 | +import java.util.Set; | ||
34 | +import java.util.concurrent.ExecutorService; | ||
35 | +import java.util.stream.Collectors; | ||
36 | + | ||
37 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
38 | +import static org.onlab.util.Tools.groupedThreads; | ||
39 | +import static org.onosproject.openstacknetworking.switching.Constants.*; | ||
40 | +import static org.slf4j.LoggerFactory.getLogger; | ||
41 | + | ||
42 | +/** | ||
43 | + * Provides abstract virtual machine handler. | ||
44 | + */ | ||
45 | +public abstract class AbstractVmHandler { | ||
46 | + protected final Logger log = getLogger(getClass()); | ||
47 | + | ||
48 | + protected final ExecutorService eventExecutor = newSingleThreadScheduledExecutor( | ||
49 | + groupedThreads(this.getClass().getSimpleName(), "event-handler")); | ||
50 | + | ||
51 | + protected CoreService coreService; | ||
52 | + protected MastershipService mastershipService; | ||
53 | + protected HostService hostService; | ||
54 | + | ||
55 | + protected ApplicationId appId; | ||
56 | + protected HostListener hostListener = new InternalHostListener(); | ||
57 | + | ||
58 | + protected void activate() { | ||
59 | + ServiceDirectory services = new DefaultServiceDirectory(); | ||
60 | + coreService = services.get(CoreService.class); | ||
61 | + mastershipService = services.get(MastershipService.class); | ||
62 | + hostService = services.get(HostService.class); | ||
63 | + | ||
64 | + appId = coreService.registerApplication(Constants.APP_ID); | ||
65 | + hostService.addListener(hostListener); | ||
66 | + | ||
67 | + log.info("Started"); | ||
68 | + } | ||
69 | + | ||
70 | + protected void deactivate() { | ||
71 | + hostService.removeListener(hostListener); | ||
72 | + eventExecutor.shutdown(); | ||
73 | + | ||
74 | + log.info("Stopped"); | ||
75 | + } | ||
76 | + | ||
77 | + abstract void hostDetected(Host host); | ||
78 | + | ||
79 | + abstract void hostRemoved(Host host); | ||
80 | + | ||
81 | + protected boolean isValidHost(Host host) { | ||
82 | + return !host.ipAddresses().isEmpty() && | ||
83 | + host.annotations().value(VXLAN_ID) != null && | ||
84 | + host.annotations().value(NETWORK_ID) != null && | ||
85 | + host.annotations().value(TENANT_ID) != null && | ||
86 | + host.annotations().value(PORT_ID) != null; | ||
87 | + } | ||
88 | + | ||
89 | + protected Set<Host> getVmsInDifferentCnode(Host host) { | ||
90 | + return Tools.stream(hostService.getHosts()) | ||
91 | + .filter(h -> !h.location().deviceId().equals(host.location().deviceId())) | ||
92 | + .filter(this::isValidHost) | ||
93 | + .filter(h -> Objects.equals(getVni(h), getVni(host))) | ||
94 | + .collect(Collectors.toSet()); | ||
95 | + } | ||
96 | + | ||
97 | + protected Optional<Host> getVmByPortId(String portId) { | ||
98 | + return Tools.stream(hostService.getHosts()) | ||
99 | + .filter(this::isValidHost) | ||
100 | + .filter(host -> host.annotations().value(PORT_ID).equals(portId)) | ||
101 | + .findFirst(); | ||
102 | + } | ||
103 | + | ||
104 | + protected Ip4Address getIp(Host host) { | ||
105 | + return host.ipAddresses().stream().findFirst().get().getIp4Address(); | ||
106 | + } | ||
107 | + | ||
108 | + protected String getVni(Host host) { | ||
109 | + return host.annotations().value(VXLAN_ID); | ||
110 | + } | ||
111 | + | ||
112 | + protected String getTenantId(Host host) { | ||
113 | + return host.annotations().value(TENANT_ID); | ||
114 | + } | ||
115 | + | ||
116 | + private class InternalHostListener implements HostListener { | ||
117 | + | ||
118 | + @Override | ||
119 | + public void event(HostEvent event) { | ||
120 | + Host host = event.subject(); | ||
121 | + if (!mastershipService.isLocalMaster(host.location().deviceId())) { | ||
122 | + // do not allow to proceed without mastership | ||
123 | + return; | ||
124 | + } | ||
125 | + | ||
126 | + if (!isValidHost(host)) { | ||
127 | + log.debug("Invalid host event, ignore it {}", host); | ||
128 | + return; | ||
129 | + } | ||
130 | + | ||
131 | + switch (event.type()) { | ||
132 | + case HOST_UPDATED: | ||
133 | + case HOST_ADDED: | ||
134 | + eventExecutor.execute(() -> hostDetected(host)); | ||
135 | + break; | ||
136 | + case HOST_REMOVED: | ||
137 | + eventExecutor.execute(() -> hostRemoved(host)); | ||
138 | + break; | ||
139 | + default: | ||
140 | + break; | ||
141 | + } | ||
142 | + } | ||
143 | + } | ||
144 | +} |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.openstacknetworking.switching; | ||
17 | + | ||
18 | +import org.onlab.packet.Ip4Address; | ||
19 | +import org.onlab.packet.Ip4Prefix; | ||
20 | +import org.onlab.packet.IpPrefix; | ||
21 | + | ||
22 | +/** | ||
23 | + * Provides constants used in OpenStack node services. | ||
24 | + */ | ||
25 | +public final class Constants { | ||
26 | + | ||
27 | + private Constants() { | ||
28 | + } | ||
29 | + | ||
30 | + public static final String APP_ID = "org.onosproject.openstackswitching"; | ||
31 | + | ||
32 | + public static final String PORTNAME_PREFIX_VM = "tap"; | ||
33 | + public static final String PORTNAME_PREFIX_ROUTER = "qr-"; | ||
34 | + public static final String PORTNAME_PREFIX_TUNNEL = "vxlan"; | ||
35 | + | ||
36 | + // TODO remove this | ||
37 | + public static final String ROUTER_INTERFACE = "network:router_interface"; | ||
38 | + public static final String DEVICE_OWNER_GATEWAY = "network:router_gateway"; | ||
39 | + | ||
40 | + public static final Ip4Address DNS_SERVER_IP = Ip4Address.valueOf("8.8.8.8"); | ||
41 | + public static final IpPrefix IP_PREFIX_ANY = Ip4Prefix.valueOf("0.0.0.0/0"); | ||
42 | + public static final int DHCP_INFINITE_LEASE = -1; | ||
43 | + | ||
44 | + public static final String NETWORK_ID = "networkId"; | ||
45 | + public static final String PORT_ID = "portId"; | ||
46 | + public static final String VXLAN_ID = "vxlanId"; | ||
47 | + public static final String TENANT_ID = "tenantId"; | ||
48 | + public static final String GATEWAY_IP = "gatewayIp"; | ||
49 | + public static final String CREATE_TIME = "createTime"; | ||
50 | + | ||
51 | + public static final int SWITCHING_RULE_PRIORITY = 30000; | ||
52 | + public static final int TUNNELTAG_RULE_PRIORITY = 30000; | ||
53 | + public static final int ACL_RULE_PRIORITY = 30000; | ||
54 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +/* | ||
2 | +* Copyright 2016-present Open Networking Laboratory | ||
3 | +* | ||
4 | +* Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | +* you may not use this file except in compliance with the License. | ||
6 | +* You may obtain a copy of the License at | ||
7 | +* | ||
8 | +* http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | +* | ||
10 | +* Unless required by applicable law or agreed to in writing, software | ||
11 | +* distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | +* See the License for the specific language governing permissions and | ||
14 | +* limitations under the License. | ||
15 | +*/ | ||
16 | +package org.onosproject.openstacknetworking.switching; | ||
17 | + | ||
18 | +import com.google.common.base.Strings; | ||
19 | +import com.google.common.collect.Sets; | ||
20 | +import org.apache.felix.scr.annotations.Activate; | ||
21 | +import org.apache.felix.scr.annotations.Component; | ||
22 | +import org.apache.felix.scr.annotations.Deactivate; | ||
23 | +import org.apache.felix.scr.annotations.Modified; | ||
24 | +import org.apache.felix.scr.annotations.Property; | ||
25 | +import org.apache.felix.scr.annotations.Reference; | ||
26 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
27 | +import org.onlab.packet.ARP; | ||
28 | +import org.onlab.packet.Ethernet; | ||
29 | +import org.onlab.packet.Ip4Address; | ||
30 | +import org.onlab.packet.IpAddress; | ||
31 | +import org.onlab.packet.MacAddress; | ||
32 | +import org.onlab.util.Tools; | ||
33 | +import org.onosproject.net.Host; | ||
34 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
35 | +import org.onosproject.net.flow.TrafficTreatment; | ||
36 | +import org.onosproject.net.packet.DefaultOutboundPacket; | ||
37 | +import org.onosproject.net.packet.PacketContext; | ||
38 | +import org.onosproject.net.packet.PacketProcessor; | ||
39 | +import org.onosproject.net.packet.PacketService; | ||
40 | +import org.onosproject.openstackinterface.OpenstackInterfaceService; | ||
41 | +import org.onosproject.openstackinterface.OpenstackNetwork; | ||
42 | +import org.onosproject.openstackinterface.OpenstackPort; | ||
43 | +import org.osgi.service.component.ComponentContext; | ||
44 | +import org.slf4j.Logger; | ||
45 | +import org.slf4j.LoggerFactory; | ||
46 | +import java.nio.ByteBuffer; | ||
47 | +import java.util.Dictionary; | ||
48 | +import java.util.Set; | ||
49 | + | ||
50 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
51 | +import static org.onosproject.openstacknetworking.switching.Constants.*; | ||
52 | + | ||
53 | +/** | ||
54 | + * Handles ARP packet from VMs. | ||
55 | + */ | ||
56 | +@Component(immediate = true) | ||
57 | +public final class OpenstackArpHandler extends AbstractVmHandler { | ||
58 | + | ||
59 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
60 | + | ||
61 | + private static final String GATEWAY_MAC = "gatewayMac"; | ||
62 | + private static final String DEFAULT_GATEWAY_MAC = "1f:1f:1f:1f:1f:1f"; | ||
63 | + | ||
64 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
65 | + protected PacketService packetService; | ||
66 | + | ||
67 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
68 | + protected OpenstackInterfaceService openstackService; | ||
69 | + | ||
70 | + @Property(name = GATEWAY_MAC, value = DEFAULT_GATEWAY_MAC, | ||
71 | + label = "Fake MAC address for virtual network subnet gateway") | ||
72 | + private String gatewayMac = DEFAULT_GATEWAY_MAC; | ||
73 | + | ||
74 | + private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); | ||
75 | + private final Set<Ip4Address> gateways = Sets.newConcurrentHashSet(); | ||
76 | + | ||
77 | + @Activate | ||
78 | + protected void activate() { | ||
79 | + packetService.addProcessor(packetProcessor, PacketProcessor.director(0)); | ||
80 | + super.activate(); | ||
81 | + } | ||
82 | + | ||
83 | + @Deactivate | ||
84 | + protected void deactivate() { | ||
85 | + packetService.removeProcessor(packetProcessor); | ||
86 | + super.deactivate(); | ||
87 | + } | ||
88 | + | ||
89 | + @Modified | ||
90 | + protected void modified(ComponentContext context) { | ||
91 | + Dictionary<?, ?> properties = context.getProperties(); | ||
92 | + String updatedMac; | ||
93 | + | ||
94 | + updatedMac = Tools.get(properties, GATEWAY_MAC); | ||
95 | + if (!Strings.isNullOrEmpty(updatedMac) && !updatedMac.equals(gatewayMac)) { | ||
96 | + gatewayMac = updatedMac; | ||
97 | + } | ||
98 | + | ||
99 | + log.info("Modified"); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Processes ARP request packets. | ||
104 | + * It checks if the target IP is owned by a known host first and then ask to | ||
105 | + * OpenStack if it's not. This ARP proxy does not support overlapping IP. | ||
106 | + * | ||
107 | + * @param context packet context | ||
108 | + * @param ethPacket ethernet packet | ||
109 | + */ | ||
110 | + private void processPacketIn(PacketContext context, Ethernet ethPacket) { | ||
111 | + ARP arpPacket = (ARP) ethPacket.getPayload(); | ||
112 | + if (arpPacket.getOpCode() != ARP.OP_REQUEST) { | ||
113 | + return; | ||
114 | + } | ||
115 | + | ||
116 | + Ip4Address targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()); | ||
117 | + MacAddress replyMac = gateways.contains(targetIp) ? MacAddress.valueOf(gatewayMac) : | ||
118 | + getMacFromHostService(targetIp); | ||
119 | + if (replyMac.equals(MacAddress.NONE)) { | ||
120 | + replyMac = getMacFromOpenstack(targetIp); | ||
121 | + } | ||
122 | + | ||
123 | + if (replyMac == MacAddress.NONE) { | ||
124 | + log.debug("Failed to find MAC address for {}", targetIp.toString()); | ||
125 | + return; | ||
126 | + } | ||
127 | + | ||
128 | + Ethernet ethReply = ARP.buildArpReply( | ||
129 | + targetIp.getIp4Address(), | ||
130 | + replyMac, | ||
131 | + ethPacket); | ||
132 | + | ||
133 | + TrafficTreatment treatment = DefaultTrafficTreatment.builder() | ||
134 | + .setOutput(context.inPacket().receivedFrom().port()) | ||
135 | + .build(); | ||
136 | + | ||
137 | + packetService.emit(new DefaultOutboundPacket( | ||
138 | + context.inPacket().receivedFrom().deviceId(), | ||
139 | + treatment, | ||
140 | + ByteBuffer.wrap(ethReply.serialize()))); | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Returns MAC address of a host with a given target IP address by asking to | ||
145 | + * OpenStack. It does not support overlapping IP. | ||
146 | + * | ||
147 | + * @param targetIp target ip address | ||
148 | + * @return mac address, or null if it fails to fetch the mac | ||
149 | + */ | ||
150 | + private MacAddress getMacFromOpenstack(IpAddress targetIp) { | ||
151 | + checkNotNull(targetIp); | ||
152 | + | ||
153 | + OpenstackPort openstackPort = openstackService.ports() | ||
154 | + .stream() | ||
155 | + .filter(port -> port.fixedIps().containsValue(targetIp.getIp4Address())) | ||
156 | + .findFirst() | ||
157 | + .orElse(null); | ||
158 | + | ||
159 | + if (openstackPort != null) { | ||
160 | + log.debug("Found MAC from OpenStack for {}", targetIp.toString()); | ||
161 | + return openstackPort.macAddress(); | ||
162 | + } else { | ||
163 | + return MacAddress.NONE; | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Returns MAC address of a host with a given target IP address by asking to | ||
169 | + * host service. It does not support overlapping IP. | ||
170 | + * | ||
171 | + * @param targetIp target ip | ||
172 | + * @return mac address, or null if it fails to find the mac | ||
173 | + */ | ||
174 | + private MacAddress getMacFromHostService(IpAddress targetIp) { | ||
175 | + checkNotNull(targetIp); | ||
176 | + | ||
177 | + Host host = hostService.getHostsByIp(targetIp) | ||
178 | + .stream() | ||
179 | + .findFirst() | ||
180 | + .orElse(null); | ||
181 | + | ||
182 | + if (host != null) { | ||
183 | + log.debug("Found MAC from host service for {}", targetIp.toString()); | ||
184 | + return host.mac(); | ||
185 | + } else { | ||
186 | + return MacAddress.NONE; | ||
187 | + } | ||
188 | + } | ||
189 | + | ||
190 | + @Override | ||
191 | + protected void hostDetected(Host host) { | ||
192 | + OpenstackNetwork osNet = openstackService.network(host.annotations().value(NETWORK_ID)); | ||
193 | + if (osNet == null) { | ||
194 | + log.warn("Failed to get OpenStack network for {}", host); | ||
195 | + return; | ||
196 | + } | ||
197 | + osNet.subnets().stream() | ||
198 | + .forEach(subnet -> gateways.add(Ip4Address.valueOf(subnet.gatewayIp()))); | ||
199 | + } | ||
200 | + | ||
201 | + @Override | ||
202 | + protected void hostRemoved(Host host) { | ||
203 | + // TODO remove subnet gateway from gateways if no hosts exists on that subnet | ||
204 | + } | ||
205 | + | ||
206 | + private class InternalPacketProcessor implements PacketProcessor { | ||
207 | + | ||
208 | + @Override | ||
209 | + public void process(PacketContext context) { | ||
210 | + if (context.isHandled()) { | ||
211 | + return; | ||
212 | + } | ||
213 | + | ||
214 | + Ethernet ethPacket = context.inPacket().parsed(); | ||
215 | + if (ethPacket == null || ethPacket.getEtherType() != Ethernet.TYPE_ARP) { | ||
216 | + return; | ||
217 | + } | ||
218 | + processPacketIn(context, ethPacket); | ||
219 | + } | ||
220 | + } | ||
221 | +} |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
... | @@ -15,16 +15,7 @@ | ... | @@ -15,16 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.openstacknetworking.web; | 16 | package org.onosproject.openstacknetworking.web; |
17 | 17 | ||
18 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
19 | -import com.fasterxml.jackson.databind.node.ObjectNode; | ||
20 | -import org.onosproject.openstackinterface.OpenstackPort; | ||
21 | -import org.onosproject.openstackinterface.web.OpenstackPortCodec; | ||
22 | -import org.onosproject.openstacknetworking.OpenstackPortInfo; | ||
23 | -import org.onosproject.openstacknetworking.OpenstackRoutingService; | ||
24 | -import org.onosproject.openstacknetworking.OpenstackSwitchingService; | ||
25 | import org.onosproject.rest.AbstractWebResource; | 18 | import org.onosproject.rest.AbstractWebResource; |
26 | -import org.slf4j.Logger; | ||
27 | -import org.slf4j.LoggerFactory; | ||
28 | 19 | ||
29 | import javax.ws.rs.Consumes; | 20 | import javax.ws.rs.Consumes; |
30 | import javax.ws.rs.DELETE; | 21 | import javax.ws.rs.DELETE; |
... | @@ -43,47 +34,16 @@ import java.io.InputStream; | ... | @@ -43,47 +34,16 @@ import java.io.InputStream; |
43 | @Path("ports") | 34 | @Path("ports") |
44 | public class OpenstackPortWebResource extends AbstractWebResource { | 35 | public class OpenstackPortWebResource extends AbstractWebResource { |
45 | 36 | ||
46 | - private final Logger log = LoggerFactory.getLogger(getClass()); | ||
47 | - private static final String PORTNAME_PREFIX_VM = "tap"; | ||
48 | - private static final OpenstackPortCodec PORT_CODEC = new OpenstackPortCodec(); | ||
49 | - | ||
50 | @POST | 37 | @POST |
51 | @Consumes(MediaType.APPLICATION_JSON) | 38 | @Consumes(MediaType.APPLICATION_JSON) |
52 | @Produces(MediaType.APPLICATION_JSON) | 39 | @Produces(MediaType.APPLICATION_JSON) |
53 | public Response createPorts(InputStream input) { | 40 | public Response createPorts(InputStream input) { |
54 | - try { | ||
55 | - ObjectMapper mapper = new ObjectMapper(); | ||
56 | - ObjectNode portNode = (ObjectNode) mapper.readTree(input); | ||
57 | - | ||
58 | - OpenstackPort openstackPort = PORT_CODEC.decode(portNode, this); | ||
59 | - OpenstackSwitchingService switchingService = | ||
60 | - getService(OpenstackSwitchingService.class); | ||
61 | - switchingService.createPorts(openstackPort); | ||
62 | - | ||
63 | - log.debug("REST API ports is called with {}", portNode.toString()); | ||
64 | return Response.status(Response.Status.OK).build(); | 41 | return Response.status(Response.Status.OK).build(); |
65 | - | ||
66 | - } catch (Exception e) { | ||
67 | - log.error("Creates Port failed because of exception {}", | ||
68 | - e.toString()); | ||
69 | - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) | ||
70 | - .build(); | ||
71 | - } | ||
72 | } | 42 | } |
73 | 43 | ||
74 | @Path("{portUUID}") | 44 | @Path("{portUUID}") |
75 | @DELETE | 45 | @DELETE |
76 | public Response deletePorts(@PathParam("portUUID") String id) { | 46 | public Response deletePorts(@PathParam("portUUID") String id) { |
77 | - OpenstackSwitchingService switchingService = | ||
78 | - getService(OpenstackSwitchingService.class); | ||
79 | - OpenstackPortInfo portInfo = switchingService.openstackPortInfo() | ||
80 | - .get(PORTNAME_PREFIX_VM.concat(id.substring(0, 11))); | ||
81 | - OpenstackRoutingService routingService = | ||
82 | - getService(OpenstackRoutingService.class); | ||
83 | - routingService.checkDisassociatedFloatingIp(id, portInfo); | ||
84 | - | ||
85 | - switchingService.removePort(id); | ||
86 | - | ||
87 | return Response.noContent().build(); | 47 | return Response.noContent().build(); |
88 | } | 48 | } |
89 | 49 | ||
... | @@ -92,23 +52,7 @@ public class OpenstackPortWebResource extends AbstractWebResource { | ... | @@ -92,23 +52,7 @@ public class OpenstackPortWebResource extends AbstractWebResource { |
92 | @Consumes(MediaType.APPLICATION_JSON) | 52 | @Consumes(MediaType.APPLICATION_JSON) |
93 | @Produces(MediaType.APPLICATION_JSON) | 53 | @Produces(MediaType.APPLICATION_JSON) |
94 | public Response updatePorts(InputStream input) { | 54 | public Response updatePorts(InputStream input) { |
95 | - try { | 55 | + // TODO call security group update here |
96 | - ObjectMapper mapper = new ObjectMapper(); | ||
97 | - ObjectNode portNode = (ObjectNode) mapper.readTree(input); | ||
98 | - | ||
99 | - OpenstackPort openstackPort = PORT_CODEC.decode(portNode, this); | ||
100 | - OpenstackSwitchingService switchingService = | ||
101 | - getService(OpenstackSwitchingService.class); | ||
102 | - switchingService.updatePort(openstackPort); | ||
103 | - | ||
104 | - log.debug("REST API update port is called with {}", portNode.toString()); | ||
105 | return Response.status(Response.Status.OK).build(); | 56 | return Response.status(Response.Status.OK).build(); |
106 | - | ||
107 | - } catch (Exception e) { | ||
108 | - log.error("Update Port failed because of exception {}", | ||
109 | - e.toString()); | ||
110 | - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) | ||
111 | - .build(); | ||
112 | - } | ||
113 | } | 57 | } |
114 | } | 58 | } | ... | ... |
... | @@ -16,5 +16,5 @@ onos_app ( | ... | @@ -16,5 +16,5 @@ onos_app ( |
16 | category = 'Utility', | 16 | category = 'Utility', |
17 | url = 'http://onosproject.org', | 17 | url = 'http://onosproject.org', |
18 | description = 'SONA Openstack Node Bootstrap Application.', | 18 | description = 'SONA Openstack Node Bootstrap Application.', |
19 | - required_app = [ 'org.onosproject.ovsdb-base' ], | 19 | + required_apps = [ 'org.onosproject.ovsdb-base', 'org.onosproject.drivers.ovsdb' ] |
20 | ) | 20 | ) | ... | ... |
... | @@ -38,7 +38,8 @@ | ... | @@ -38,7 +38,8 @@ |
38 | <onos.app.url>http://onosproject.org</onos.app.url> | 38 | <onos.app.url>http://onosproject.org</onos.app.url> |
39 | <onos.app.readme>SONA Openstack Node Bootstrap Application</onos.app.readme> | 39 | <onos.app.readme>SONA Openstack Node Bootstrap Application</onos.app.readme> |
40 | <onos.app.requires> | 40 | <onos.app.requires> |
41 | - org.onosproject.ovsdb-base | 41 | + org.onosproject.ovsdb-base, |
42 | + org.onosproject.drivers.ovsdb | ||
42 | </onos.app.requires> | 43 | </onos.app.requires> |
43 | </properties> | 44 | </properties> |
44 | 45 | ... | ... |
... | @@ -242,7 +242,7 @@ public final class OpenstackNodeManager implements OpenstackNodeService { | ... | @@ -242,7 +242,7 @@ public final class OpenstackNodeManager implements OpenstackNodeService { |
242 | deviceService.removeListener(deviceListener); | 242 | deviceService.removeListener(deviceListener); |
243 | nodeStore.removeListener(nodeStoreListener); | 243 | nodeStore.removeListener(nodeStoreListener); |
244 | 244 | ||
245 | - componentConfigService.unregisterProperties(getClass(), true); | 245 | + componentConfigService.unregisterProperties(getClass(), false); |
246 | configRegistry.unregisterConfigFactory(configFactory); | 246 | configRegistry.unregisterConfigFactory(configFactory); |
247 | 247 | ||
248 | leadershipService.withdraw(appId.name()); | 248 | leadershipService.withdraw(appId.name()); | ... | ... |
... | @@ -54,8 +54,8 @@ APPS = [ | ... | @@ -54,8 +54,8 @@ APPS = [ |
54 | '//apps/mlb:onos-apps-mlb-oar', | 54 | '//apps/mlb:onos-apps-mlb-oar', |
55 | '//apps/openstackinterface:onos-apps-openstackinterface-oar', | 55 | '//apps/openstackinterface:onos-apps-openstackinterface-oar', |
56 | '//apps/openstacknetworking:onos-apps-openstacknetworking-oar', | 56 | '//apps/openstacknetworking:onos-apps-openstacknetworking-oar', |
57 | - '//apps/openstacknetworking/openstackrouting:onos-apps-openstacknetworking-openstackrouting-oar', | 57 | + '//apps/openstacknetworking/routing:onos-apps-openstacknetworking-routing-oar', |
58 | - '//apps/openstacknetworking/openstackswitching:onos-apps-openstacknetworking-openstackswitching-oar', | 58 | + '//apps/openstacknetworking/switching:onos-apps-openstacknetworking-switching-oar', |
59 | '//apps/mobility:onos-apps-mobility-oar', | 59 | '//apps/mobility:onos-apps-mobility-oar', |
60 | '//apps/optical:onos-apps-optical-oar', | 60 | '//apps/optical:onos-apps-optical-oar', |
61 | '//apps/pathpainter:onos-apps-pathpainter-oar', | 61 | '//apps/pathpainter:onos-apps-pathpainter-oar', | ... | ... |
-
Please register or login to post a comment