Committed by
Gerrit Code Review
Implemented dummy Neutron ML2 plugin handler
- Added REST handler for Neutron ML2 ONOS mech driver - Made cordvtn ARP proxy to handle request for host, too - Now cordvtn utilizes openstackSwitching only as a Neutron REST client Change-Id: I6890b6651ddcb9d8cf33fb326e9f0eb721b536a5
Showing
6 changed files
with
239 additions
and
8 deletions
... | @@ -172,7 +172,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro | ... | @@ -172,7 +172,7 @@ public class CordVtn extends AbstractProvider implements CordVtnService, HostPro |
172 | mastershipService, | 172 | mastershipService, |
173 | DEFAULT_TUNNEL); | 173 | DEFAULT_TUNNEL); |
174 | 174 | ||
175 | - arpProxy = new CordVtnArpProxy(appId, packetService); | 175 | + arpProxy = new CordVtnArpProxy(appId, packetService, hostService); |
176 | packetService.addProcessor(packetProcessor, PacketProcessor.director(0)); | 176 | packetService.addProcessor(packetProcessor, PacketProcessor.director(0)); |
177 | arpProxy.requestPacket(); | 177 | arpProxy.requestPacket(); |
178 | 178 | ... | ... |
... | @@ -28,6 +28,7 @@ import org.onosproject.net.flow.DefaultTrafficSelector; | ... | @@ -28,6 +28,7 @@ import org.onosproject.net.flow.DefaultTrafficSelector; |
28 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 28 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
29 | import org.onosproject.net.flow.TrafficSelector; | 29 | import org.onosproject.net.flow.TrafficSelector; |
30 | import org.onosproject.net.flow.TrafficTreatment; | 30 | import org.onosproject.net.flow.TrafficTreatment; |
31 | +import org.onosproject.net.host.HostService; | ||
31 | import org.onosproject.net.packet.DefaultOutboundPacket; | 32 | import org.onosproject.net.packet.DefaultOutboundPacket; |
32 | import org.onosproject.net.packet.PacketContext; | 33 | import org.onosproject.net.packet.PacketContext; |
33 | import org.onosproject.net.packet.PacketPriority; | 34 | import org.onosproject.net.packet.PacketPriority; |
... | @@ -50,6 +51,7 @@ public class CordVtnArpProxy { | ... | @@ -50,6 +51,7 @@ public class CordVtnArpProxy { |
50 | 51 | ||
51 | private final ApplicationId appId; | 52 | private final ApplicationId appId; |
52 | private final PacketService packetService; | 53 | private final PacketService packetService; |
54 | + private final HostService hostService; | ||
53 | 55 | ||
54 | private Set<Ip4Address> serviceIPs = Sets.newHashSet(); | 56 | private Set<Ip4Address> serviceIPs = Sets.newHashSet(); |
55 | 57 | ||
... | @@ -59,9 +61,10 @@ public class CordVtnArpProxy { | ... | @@ -59,9 +61,10 @@ public class CordVtnArpProxy { |
59 | * @param appId application id | 61 | * @param appId application id |
60 | * @param packetService packet service | 62 | * @param packetService packet service |
61 | */ | 63 | */ |
62 | - public CordVtnArpProxy(ApplicationId appId, PacketService packetService) { | 64 | + public CordVtnArpProxy(ApplicationId appId, PacketService packetService, HostService hostService) { |
63 | this.appId = appId; | 65 | this.appId = appId; |
64 | this.packetService = packetService; | 66 | this.packetService = packetService; |
67 | + this.hostService = hostService; | ||
65 | } | 68 | } |
66 | 69 | ||
67 | /** | 70 | /** |
... | @@ -124,14 +127,16 @@ public class CordVtnArpProxy { | ... | @@ -124,14 +127,16 @@ public class CordVtnArpProxy { |
124 | */ | 127 | */ |
125 | public void processArpPacket(PacketContext context, Ethernet ethPacket, MacAddress gatewayMac) { | 128 | public void processArpPacket(PacketContext context, Ethernet ethPacket, MacAddress gatewayMac) { |
126 | ARP arpPacket = (ARP) ethPacket.getPayload(); | 129 | ARP arpPacket = (ARP) ethPacket.getPayload(); |
127 | - Ip4Address targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()); | 130 | + if (arpPacket.getOpCode() != ARP.OP_REQUEST) { |
128 | - | ||
129 | - if (arpPacket.getOpCode() != ARP.OP_REQUEST || !serviceIPs.contains(targetIp)) { | ||
130 | return; | 131 | return; |
131 | } | 132 | } |
132 | 133 | ||
133 | - if (gatewayMac.equals(MacAddress.NONE)) { | 134 | + Ip4Address targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()); |
134 | - log.debug("Gateway mac address is not set, ignoring ARP request"); | 135 | + MacAddress macAddr = serviceIPs.contains(targetIp) ? |
136 | + gatewayMac : getMacFromHostService(targetIp); | ||
137 | + | ||
138 | + if (macAddr.equals(MacAddress.NONE)) { | ||
139 | + log.debug("Failed to find MAC for {}", targetIp.toString()); | ||
135 | context.block(); | 140 | context.block(); |
136 | return; | 141 | return; |
137 | } | 142 | } |
... | @@ -205,4 +210,27 @@ public class CordVtnArpProxy { | ... | @@ -205,4 +210,27 @@ public class CordVtnArpProxy { |
205 | eth.setPayload(arp); | 210 | eth.setPayload(arp); |
206 | return eth; | 211 | return eth; |
207 | } | 212 | } |
213 | + | ||
214 | + /** | ||
215 | + * Returns MAC address of a host with a given target IP address by asking to | ||
216 | + * host service. It does not support overlapping IP. | ||
217 | + * | ||
218 | + * @param targetIp target ip | ||
219 | + * @return mac address, or NONE mac address if it fails to find the mac | ||
220 | + */ | ||
221 | + private MacAddress getMacFromHostService(IpAddress targetIp) { | ||
222 | + checkNotNull(targetIp); | ||
223 | + | ||
224 | + Host host = hostService.getHostsByIp(targetIp) | ||
225 | + .stream() | ||
226 | + .findFirst() | ||
227 | + .orElse(null); | ||
228 | + | ||
229 | + if (host != null) { | ||
230 | + log.debug("Found MAC from host service for {}", targetIp.toString()); | ||
231 | + return host.mac(); | ||
232 | + } else { | ||
233 | + return MacAddress.NONE; | ||
234 | + } | ||
235 | + } | ||
208 | } | 236 | } | ... | ... |
... | @@ -26,6 +26,9 @@ import java.util.Set; | ... | @@ -26,6 +26,9 @@ import java.util.Set; |
26 | public class CordVtnWebApplication extends AbstractWebApplication { | 26 | public class CordVtnWebApplication extends AbstractWebApplication { |
27 | @Override | 27 | @Override |
28 | public Set<Class<?>> getClasses() { | 28 | public Set<Class<?>> getClasses() { |
29 | - return getClasses(ServiceDependencyWebResource.class); | 29 | + return getClasses(ServiceDependencyWebResource.class, |
30 | + NeutronMl2NetworksWebResource.class, | ||
31 | + NeutronMl2SubnetsWebResource.class, | ||
32 | + NeutronMl2PortsWebResource.class); | ||
30 | } | 33 | } |
31 | } | 34 | } | ... | ... |
apps/cordvtn/src/main/java/org/onosproject/cordvtn/rest/NeutronMl2NetworksWebResource.java
0 → 100644
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.cordvtn.rest; | ||
17 | + | ||
18 | +import org.onosproject.rest.AbstractWebResource; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory; | ||
21 | + | ||
22 | +import javax.ws.rs.Consumes; | ||
23 | +import javax.ws.rs.DELETE; | ||
24 | +import javax.ws.rs.POST; | ||
25 | +import javax.ws.rs.PUT; | ||
26 | +import javax.ws.rs.Path; | ||
27 | +import javax.ws.rs.PathParam; | ||
28 | +import javax.ws.rs.Produces; | ||
29 | +import javax.ws.rs.core.MediaType; | ||
30 | +import javax.ws.rs.core.Response; | ||
31 | +import java.io.InputStream; | ||
32 | + | ||
33 | +/** | ||
34 | + * Dummy Neutron ML2 mechanism driver. | ||
35 | + * It just returns OK for networks resource requests. | ||
36 | + */ | ||
37 | +@Path("networks") | ||
38 | +public class NeutronMl2NetworksWebResource extends AbstractWebResource { | ||
39 | + protected final Logger log = LoggerFactory.getLogger(getClass()); | ||
40 | + private static final String NETWORKS_MESSAGE = "Received networks %s"; | ||
41 | + | ||
42 | + @POST | ||
43 | + @Consumes(MediaType.APPLICATION_JSON) | ||
44 | + @Produces(MediaType.APPLICATION_JSON) | ||
45 | + public Response createNetwork(InputStream input) { | ||
46 | + log.debug(String.format(NETWORKS_MESSAGE, "create")); | ||
47 | + return Response.status(Response.Status.OK).build(); | ||
48 | + } | ||
49 | + | ||
50 | + @PUT | ||
51 | + @Path("{id}") | ||
52 | + @Consumes(MediaType.APPLICATION_JSON) | ||
53 | + @Produces(MediaType.APPLICATION_JSON) | ||
54 | + public Response updateNetwork(@PathParam("id") String id, InputStream input) { | ||
55 | + log.debug(String.format(NETWORKS_MESSAGE, "update")); | ||
56 | + return Response.status(Response.Status.OK).build(); | ||
57 | + } | ||
58 | + | ||
59 | + @DELETE | ||
60 | + @Path("{id}") | ||
61 | + @Produces(MediaType.APPLICATION_JSON) | ||
62 | + public Response deleteNetwork(@PathParam("id") String id) { | ||
63 | + log.debug(String.format(NETWORKS_MESSAGE, "delete")); | ||
64 | + return Response.status(Response.Status.OK).build(); | ||
65 | + } | ||
66 | +} |
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.cordvtn.rest; | ||
17 | + | ||
18 | +import org.onosproject.rest.AbstractWebResource; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory; | ||
21 | + | ||
22 | +import javax.ws.rs.Consumes; | ||
23 | +import javax.ws.rs.DELETE; | ||
24 | +import javax.ws.rs.POST; | ||
25 | +import javax.ws.rs.PUT; | ||
26 | +import javax.ws.rs.Path; | ||
27 | +import javax.ws.rs.PathParam; | ||
28 | +import javax.ws.rs.Produces; | ||
29 | +import javax.ws.rs.core.MediaType; | ||
30 | +import javax.ws.rs.core.Response; | ||
31 | +import java.io.InputStream; | ||
32 | + | ||
33 | +/** | ||
34 | + * Dummy Neutron ML2 mechanism driver. | ||
35 | + * It just returns OK for ports resource requests. | ||
36 | + */ | ||
37 | +@Path("ports") | ||
38 | +public class NeutronMl2PortsWebResource extends AbstractWebResource { | ||
39 | + protected final Logger log = LoggerFactory.getLogger(getClass()); | ||
40 | + private static final String PORTS_MESSAGE = "Received ports %s"; | ||
41 | + | ||
42 | + @POST | ||
43 | + @Consumes(MediaType.APPLICATION_JSON) | ||
44 | + @Produces(MediaType.APPLICATION_JSON) | ||
45 | + public Response createPorts(InputStream input) { | ||
46 | + log.debug(String.format(PORTS_MESSAGE, "create")); | ||
47 | + return Response.status(Response.Status.OK).build(); | ||
48 | + } | ||
49 | + | ||
50 | + @PUT | ||
51 | + @Path("{id}") | ||
52 | + @Consumes(MediaType.APPLICATION_JSON) | ||
53 | + @Produces(MediaType.APPLICATION_JSON) | ||
54 | + public Response updatePorts(@PathParam("id") String id, InputStream input) { | ||
55 | + log.debug(String.format(PORTS_MESSAGE, "update")); | ||
56 | + return Response.status(Response.Status.OK).build(); | ||
57 | + } | ||
58 | + | ||
59 | + @Path("{id}") | ||
60 | + @DELETE | ||
61 | + @Produces(MediaType.APPLICATION_JSON) | ||
62 | + public Response deletePorts(@PathParam("id") String id) { | ||
63 | + log.debug(String.format(PORTS_MESSAGE, "delete")); | ||
64 | + return Response.status(Response.Status.OK).build(); | ||
65 | + } | ||
66 | +} |
apps/cordvtn/src/main/java/org/onosproject/cordvtn/rest/NeutronMl2SubnetsWebResource.java
0 → 100644
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.cordvtn.rest; | ||
17 | + | ||
18 | +import org.onosproject.rest.AbstractWebResource; | ||
19 | +import org.slf4j.Logger; | ||
20 | +import org.slf4j.LoggerFactory; | ||
21 | + | ||
22 | +import javax.ws.rs.Consumes; | ||
23 | +import javax.ws.rs.DELETE; | ||
24 | +import javax.ws.rs.POST; | ||
25 | +import javax.ws.rs.PUT; | ||
26 | +import javax.ws.rs.Path; | ||
27 | +import javax.ws.rs.PathParam; | ||
28 | +import javax.ws.rs.Produces; | ||
29 | +import javax.ws.rs.core.MediaType; | ||
30 | +import javax.ws.rs.core.Response; | ||
31 | +import java.io.InputStream; | ||
32 | + | ||
33 | +/** | ||
34 | + * Dummy Neutron ML2 mechanism driver. | ||
35 | + * It just returns OK for subnets resource requests. | ||
36 | + */ | ||
37 | +@Path("subnets") | ||
38 | +public class NeutronMl2SubnetsWebResource extends AbstractWebResource { | ||
39 | + protected final Logger log = LoggerFactory.getLogger(getClass()); | ||
40 | + private static final String SUBNETS_MESSAGE = "Received subnets %s"; | ||
41 | + | ||
42 | + @POST | ||
43 | + @Consumes(MediaType.APPLICATION_JSON) | ||
44 | + @Produces(MediaType.APPLICATION_JSON) | ||
45 | + public Response createSubnet(InputStream input) { | ||
46 | + log.debug(String.format(SUBNETS_MESSAGE, "create")); | ||
47 | + return Response.status(Response.Status.OK).build(); | ||
48 | + } | ||
49 | + | ||
50 | + | ||
51 | + @PUT | ||
52 | + @Path("{id}") | ||
53 | + @Produces(MediaType.APPLICATION_JSON) | ||
54 | + @Consumes(MediaType.APPLICATION_JSON) | ||
55 | + public Response updateSubnet(@PathParam("id") String id, InputStream input) { | ||
56 | + log.debug(String.format(SUBNETS_MESSAGE, "update")); | ||
57 | + return Response.status(Response.Status.OK).build(); | ||
58 | + | ||
59 | + } | ||
60 | + | ||
61 | + @DELETE | ||
62 | + @Path("{id}") | ||
63 | + @Produces(MediaType.APPLICATION_JSON) | ||
64 | + public Response deleteSubnet(@PathParam("id") String id) { | ||
65 | + log.debug(String.format(SUBNETS_MESSAGE, "delete")); | ||
66 | + return Response.status(Response.Status.OK).build(); | ||
67 | + } | ||
68 | +} |
-
Please register or login to post a comment