sanghoshin
Committed by Gerrit Code Review

SONA : OpenstackSwitching

 - Stateless Neutron data handling
 - Supports Nicira ext.

Change-Id: I31db161bbd06a03e2d8e6ee6abfb033215898ee7
Showing 16 changed files with 416 additions and 81 deletions
...@@ -32,7 +32,8 @@ public final class OpenstackPort { ...@@ -32,7 +32,8 @@ public final class OpenstackPort {
32 32
33 public enum PortStatus { 33 public enum PortStatus {
34 UP, 34 UP,
35 - DOWN 35 + DOWN,
36 + ACTIVE
36 } 37 }
37 38
38 private PortStatus status; 39 private PortStatus status;
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.openstackswitching; 16 package org.onosproject.openstackswitching;
17 17
18 +import org.onosproject.net.Port;
19 +
18 import java.util.Collection; 20 import java.util.Collection;
19 21
20 /** 22 /**
...@@ -64,6 +66,14 @@ public interface OpenstackSwitchingService { ...@@ -64,6 +66,14 @@ public interface OpenstackSwitchingService {
64 Collection<OpenstackPort> ports(String networkId); 66 Collection<OpenstackPort> ports(String networkId);
65 67
66 /** 68 /**
69 + * Returns port information for the port given.
70 + *
71 + * @param port port reference
72 + * @return port information
73 + */
74 + OpenstackPort port(Port port);
75 +
76 + /**
67 * Returns port information for the port ID given. 77 * Returns port information for the port ID given.
68 * 78 *
69 * @param portId Port ID 79 * @param portId Port ID
......
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
16 --> 16 -->
17 <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> 17 <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository> 18 <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository>
19 - <feature name="onos-app-openstackswitching" version="${project.version}" 19 + <feature name="${project.artifactId}" version="${project.version}"
20 description="${project.description}"> 20 description="${project.description}">
21 <feature>onos-api</feature> 21 <feature>onos-api</feature>
22 <bundle>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</bundle> 22 <bundle>mvn:${project.groupId}/onos-app-openstackswitching/${project.version}</bundle>
23 <bundle>mvn:${project.groupId}/onos-app-dhcp-api/${project.version}</bundle> 23 <bundle>mvn:${project.groupId}/onos-app-dhcp-api/${project.version}</bundle>
24 <bundle>mvn:${project.groupId}/onos-app-dhcp/${project.version}</bundle> 24 <bundle>mvn:${project.groupId}/onos-app-dhcp/${project.version}</bundle>
25 + <bundle>mvn:com.sun.jersey/jersey-client/1.19</bundle>
26 + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
25 </feature> 27 </feature>
26 </features> 28 </features>
......
...@@ -90,6 +90,11 @@ ...@@ -90,6 +90,11 @@
90 <artifactId>onos-app-dhcp-api</artifactId> 90 <artifactId>onos-app-dhcp-api</artifactId>
91 <version>${project.version}</version> 91 <version>${project.version}</version>
92 </dependency> 92 </dependency>
93 + <dependency>
94 + <groupId>com.sun.jersey</groupId>
95 + <artifactId>jersey-client</artifactId>
96 + <version>1.19</version>
97 + </dependency>
93 </dependencies> 98 </dependencies>
94 99
95 <build> 100 <build>
...@@ -110,6 +115,7 @@ ...@@ -110,6 +115,7 @@
110 javax.ws.rs, 115 javax.ws.rs,
111 javax.ws.rs.core, 116 javax.ws.rs.core,
112 com.sun.jersey.api.core, 117 com.sun.jersey.api.core,
118 + com.sun.jersey.api.client,
113 com.sun.jersey.spi.container.servlet, 119 com.sun.jersey.spi.container.servlet,
114 com.sun.jersey.server.impl.container.servlet, 120 com.sun.jersey.server.impl.container.servlet,
115 com.fasterxml.jackson.databind, 121 com.fasterxml.jackson.databind,
......
...@@ -28,7 +28,8 @@ import org.onosproject.net.packet.PacketService; ...@@ -28,7 +28,8 @@ import org.onosproject.net.packet.PacketService;
28 import org.slf4j.Logger; 28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 29 import org.slf4j.LoggerFactory;
30 import java.nio.ByteBuffer; 30 import java.nio.ByteBuffer;
31 -import java.util.Map; 31 +
32 +import static com.google.common.base.Preconditions.checkNotNull;
32 33
33 /** 34 /**
34 * Handles ARP packet from VMs. 35 * Handles ARP packet from VMs.
...@@ -38,16 +39,16 @@ public class OpenstackArpHandler { ...@@ -38,16 +39,16 @@ public class OpenstackArpHandler {
38 private static Logger log = LoggerFactory 39 private static Logger log = LoggerFactory
39 .getLogger(OpenstackArpHandler.class); 40 .getLogger(OpenstackArpHandler.class);
40 private PacketService packetService; 41 private PacketService packetService;
41 - private Map<String, OpenstackPort> openstackPortMap; 42 + private OpenstackRestHandler restHandler;
42 43
43 /** 44 /**
44 * Returns OpenstackArpHandler reference. 45 * Returns OpenstackArpHandler reference.
45 * 46 *
46 - * @param openstackPortMap 47 + * @param restHandler rest API handler reference
47 - * @param packetService 48 + * @param packetService PacketService reference
48 */ 49 */
49 - public OpenstackArpHandler(Map<String, OpenstackPort> openstackPortMap, PacketService packetService) { 50 + public OpenstackArpHandler(OpenstackRestHandler restHandler, PacketService packetService) {
50 - this.openstackPortMap = openstackPortMap; 51 + this.restHandler = checkNotNull(restHandler);
51 this.packetService = packetService; 52 this.packetService = packetService;
52 } 53 }
53 54
...@@ -68,8 +69,9 @@ public class OpenstackArpHandler { ...@@ -68,8 +69,9 @@ public class OpenstackArpHandler {
68 //Searches the Dst MAC Address based on openstackPortMap 69 //Searches the Dst MAC Address based on openstackPortMap
69 MacAddress macAddress = null; 70 MacAddress macAddress = null;
70 71
71 - OpenstackPort openstackPort = openstackPortMap.values().stream().filter(e -> e.fixedIps(). 72 + OpenstackPort openstackPort = restHandler.getPorts().stream().
72 - containsValue(Ip4Address.valueOf(dstIPAddress))).findAny().orElse(null); 73 + filter(e -> e.fixedIps().containsValue(Ip4Address.valueOf(
74 + dstIPAddress))).findAny().orElse(null);
73 75
74 if (openstackPort != null) { 76 if (openstackPort != null) {
75 macAddress = openstackPort.macAddress(); 77 macAddress = openstackPort.macAddress();
......
1 +/*
2 + * Copyright 2015 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.openstackswitching;
17 +
18 +import com.fasterxml.jackson.databind.ObjectMapper;
19 +import com.fasterxml.jackson.databind.node.ArrayNode;
20 +import com.fasterxml.jackson.databind.node.ObjectNode;
21 +import com.google.common.collect.Lists;
22 +import com.sun.jersey.api.client.Client;
23 +import com.sun.jersey.api.client.WebResource;
24 +import org.onosproject.openstackswitching.web.OpenstackNetworkCodec;
25 +import org.onosproject.openstackswitching.web.OpenstackPortCodec;
26 +import org.onosproject.openstackswitching.web.OpenstackSubnetCodec;
27 +import org.slf4j.Logger;
28 +import javax.ws.rs.core.MediaType;
29 +import java.io.IOException;
30 +import java.util.Collection;
31 +import java.util.List;
32 +
33 +import static com.google.common.base.Preconditions.checkNotNull;
34 +import static com.google.common.net.MediaType.JSON_UTF_8;
35 +import static org.slf4j.LoggerFactory.getLogger;
36 +
37 +/**
38 + * Handles REST Calls to Openstack Neutron.
39 + *
40 + */
41 +public class OpenstackRestHandler {
42 +
43 + private final Logger log = getLogger(getClass());
44 + private String neutronUrl;
45 + private String keystoneUrl;
46 + private String tokenId;
47 + private String userName;
48 + private String pass;
49 +
50 + /**
51 + * Creates OpenstackRestHandler instance.
52 + *
53 + * @param cfg OpenstackSwitchingConfig reference
54 + */
55 + public OpenstackRestHandler(OpenstackSwitchingConfig cfg) {
56 + this.neutronUrl = checkNotNull(cfg.neutronServer());
57 + this.keystoneUrl = checkNotNull(cfg.keystoneServer());
58 + this.userName = checkNotNull(cfg.userName());
59 + this.pass = checkNotNull(cfg.password());
60 + }
61 +
62 + /**
63 + * Returns network information stored in Neutron.
64 + *
65 + * @return List of OpenstackNetwork
66 + */
67 + public Collection<OpenstackNetwork> getNetworks() {
68 +
69 + WebResource.Builder builder = getClientBuilder(neutronUrl + "networks");
70 + String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
71 + header("X-Auth-Token", getToken()).get(String.class);
72 +
73 + ObjectMapper mapper = new ObjectMapper();
74 + List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
75 + try {
76 + ObjectNode node = (ObjectNode) mapper.readTree(response);
77 + ArrayNode networkList = (ArrayNode) node.path("networks");
78 + OpenstackNetworkCodec networkCodec = new OpenstackNetworkCodec();
79 + networkList.forEach(n -> openstackNetworks.add(networkCodec.decode((ObjectNode) n, null)));
80 + } catch (IOException e) {
81 + e.printStackTrace();
82 + }
83 +
84 + log.debug("networks response:" + response);
85 + openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id()));
86 +
87 + return openstackNetworks;
88 + }
89 +
90 + /**
91 + * Returns port information stored in Neutron.
92 + *
93 + * @return List of OpenstackPort
94 + */
95 + public Collection<OpenstackPort> getPorts() {
96 +
97 + WebResource.Builder builder = getClientBuilder(neutronUrl + "ports");
98 + String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
99 + header("X-Auth-Token", getToken()).get(String.class);
100 +
101 + ObjectMapper mapper = new ObjectMapper();
102 + List<OpenstackPort> openstackPorts = Lists.newArrayList();
103 + try {
104 + ObjectNode node = (ObjectNode) mapper.readTree(response);
105 + ArrayNode portList = (ArrayNode) node.path("ports");
106 + OpenstackPortCodec portCodec = new OpenstackPortCodec();
107 + portList.forEach(p -> openstackPorts.add(portCodec.decode((ObjectNode) p, null)));
108 + } catch (IOException e) {
109 + e.printStackTrace();
110 + }
111 +
112 + log.debug("port response:" + response);
113 + openstackPorts.forEach(n -> log.debug("port ID: {}", n.id()));
114 +
115 + return openstackPorts;
116 + }
117 +
118 + /**
119 + * Returns Subnet information in Neutron.
120 + *
121 + * @return List of OpenstackSubnet
122 + */
123 + public Collection<OpenstackSubnet> getSubnets() {
124 +
125 + WebResource.Builder builder = getClientBuilder(neutronUrl + "subnets");
126 + String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
127 + header("X-Auth-Token", getToken()).get(String.class);
128 +
129 + ObjectMapper mapper = new ObjectMapper();
130 + List<OpenstackSubnet> subnets = Lists.newArrayList();
131 + try {
132 + ObjectNode node = (ObjectNode) mapper.readTree(response);
133 + ArrayNode subnetList = (ArrayNode) node.path("subnets");
134 + OpenstackSubnetCodec subnetCodec = new OpenstackSubnetCodec();
135 + subnetList.forEach(s -> subnets.add(subnetCodec.decode((ObjectNode) s, null)));
136 + } catch (IOException e) {
137 + e.printStackTrace();
138 + }
139 +
140 + log.debug("subnets response:" + response);
141 + subnets.forEach(s -> log.debug("subnet ID: {}", s.id()));
142 +
143 + return subnets;
144 + }
145 +
146 + private WebResource.Builder getClientBuilder(String uri) {
147 + Client client = Client.create();
148 + WebResource resource = client.resource(uri);
149 + return resource.accept(JSON_UTF_8.toString())
150 + .type(JSON_UTF_8.toString());
151 + }
152 +
153 + private String getToken() {
154 + if (isTokenInvalid()) {
155 + String request = "{\"auth\": {\"tenantName\": \"admin\", " +
156 + "\"passwordCredentials\": {\"username\": \"" +
157 + userName + "\",\"password\": \"" + pass + "\"}}}";
158 + WebResource.Builder builder = getClientBuilder(keystoneUrl + "tokens");
159 + String response = builder.accept(MediaType.APPLICATION_JSON).post(String.class, request);
160 +
161 + ObjectMapper mapper = new ObjectMapper();
162 + try {
163 + ObjectNode node = (ObjectNode) mapper.readTree(response);
164 + tokenId = node.path("access").path("token").path("id").asText();
165 + } catch (IOException e) {
166 + e.printStackTrace();
167 + }
168 + log.debug("token response:" + response);
169 + }
170 +
171 + return tokenId;
172 + }
173 +
174 + private boolean isTokenInvalid() {
175 + //TODO: validation check for the existing token
176 + return true;
177 + }
178 +
179 +}
...@@ -24,6 +24,10 @@ import org.onosproject.net.config.basics.BasicElementConfig; ...@@ -24,6 +24,10 @@ import org.onosproject.net.config.basics.BasicElementConfig;
24 */ 24 */
25 public class OpenstackSwitchingConfig extends Config<ApplicationId> { 25 public class OpenstackSwitchingConfig extends Config<ApplicationId> {
26 public static final String DONOTPUSH = "do_not_push_flows"; 26 public static final String DONOTPUSH = "do_not_push_flows";
27 + public static final String NEUTRON_SERVER = "neutron_server";
28 + public static final String KEYSTONE_SERVER = "keystone_server";
29 + public static final String USER_NAME = "user_name";
30 + public static final String PASSWORD = "password";
27 31
28 /** 32 /**
29 * Returns the flag whether the app pushes flows or not. 33 * Returns the flag whether the app pushes flows or not.
...@@ -36,6 +40,42 @@ public class OpenstackSwitchingConfig extends Config<ApplicationId> { ...@@ -36,6 +40,42 @@ public class OpenstackSwitchingConfig extends Config<ApplicationId> {
36 } 40 }
37 41
38 /** 42 /**
43 + * Returns the Neutron server IP address.
44 + *
45 + * @return Neutron server IP
46 + */
47 + public String neutronServer() {
48 + return get(NEUTRON_SERVER, "");
49 + }
50 +
51 + /**
52 + * Returns the Keystone server IP address.
53 + *
54 + * @return Keystone server IP
55 + */
56 + public String keystoneServer() {
57 + return get(KEYSTONE_SERVER, "");
58 + }
59 +
60 + /**
61 + * Returns the username for openstack.
62 + *
63 + * @return username for openstack
64 + */
65 + public String userName() {
66 + return get(USER_NAME, "");
67 + }
68 +
69 + /**
70 + * Returns the password for openstack.
71 + *
72 + * @return password for openstack
73 + */
74 + public String password() {
75 + return get(PASSWORD, "");
76 + }
77 +
78 + /**
39 * Sets the flag whether the app pushes flows or not. 79 * Sets the flag whether the app pushes flows or not.
40 * 80 *
41 * @param flag the flag whether the app pushes flows or not 81 * @param flag the flag whether the app pushes flows or not
...@@ -44,4 +84,44 @@ public class OpenstackSwitchingConfig extends Config<ApplicationId> { ...@@ -44,4 +84,44 @@ public class OpenstackSwitchingConfig extends Config<ApplicationId> {
44 public BasicElementConfig doNotPushFlows(boolean flag) { 84 public BasicElementConfig doNotPushFlows(boolean flag) {
45 return (BasicElementConfig) setOrClear(DONOTPUSH, flag); 85 return (BasicElementConfig) setOrClear(DONOTPUSH, flag);
46 } 86 }
87 +
88 + /**
89 + * Sets the neutron server IP address.
90 + *
91 + * @param url neutron server IP address
92 + * @return itself
93 + */
94 + public BasicElementConfig neutronServer(String url) {
95 + return (BasicElementConfig) setOrClear(NEUTRON_SERVER, url);
96 + }
97 +
98 + /**
99 + * Sets the keystone server IP address.
100 + *
101 + * @param url keystone server IP address
102 + * @return itself
103 + */
104 + public BasicElementConfig keystoneServer(String url) {
105 + return (BasicElementConfig) setOrClear(KEYSTONE_SERVER, url);
106 + }
107 +
108 + /**
109 + * Sets the username for openstack.
110 + *
111 + * @param username user name for openstack
112 + * @return itself
113 + */
114 + public BasicElementConfig userName(String username) {
115 + return (BasicElementConfig) setOrClear(USER_NAME, username);
116 + }
117 +
118 + /**
119 + * Sets the password for openstack.
120 + *
121 + * @param password password for openstack
122 + * @return itself
123 + */
124 + public BasicElementConfig password(String password) {
125 + return (BasicElementConfig) setOrClear(PASSWORD, password);
126 + }
47 } 127 }
......
...@@ -43,6 +43,9 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> { ...@@ -43,6 +43,9 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> {
43 public OpenstackNetwork decode(ObjectNode json, CodecContext context) { 43 public OpenstackNetwork decode(ObjectNode json, CodecContext context) {
44 44
45 JsonNode networkInfo = json.get(NETWORK); 45 JsonNode networkInfo = json.get(NETWORK);
46 + if (networkInfo == null) {
47 + networkInfo = json;
48 + }
46 49
47 String name = networkInfo.path(NAME).asText(); 50 String name = networkInfo.path(NAME).asText();
48 String tenantId = networkInfo.path(TENANT_ID).asText(); 51 String tenantId = networkInfo.path(TENANT_ID).asText();
......
...@@ -15,48 +15,52 @@ ...@@ -15,48 +15,52 @@
15 */ 15 */
16 package org.onosproject.openstackswitching.web; 16 package org.onosproject.openstackswitching.web;
17 17
18 -import com.fasterxml.jackson.databind.ObjectMapper;
19 -import com.fasterxml.jackson.databind.node.ObjectNode;
20 -import org.onosproject.openstackswitching.OpenstackNetwork;
21 -import org.onosproject.openstackswitching.OpenstackSwitchingService;
22 import org.onosproject.rest.AbstractWebResource; 18 import org.onosproject.rest.AbstractWebResource;
23 import org.slf4j.Logger; 19 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory; 20 import org.slf4j.LoggerFactory;
25 21
26 import javax.ws.rs.Consumes; 22 import javax.ws.rs.Consumes;
23 +import javax.ws.rs.DELETE;
27 import javax.ws.rs.POST; 24 import javax.ws.rs.POST;
25 +import javax.ws.rs.PUT;
28 import javax.ws.rs.Path; 26 import javax.ws.rs.Path;
29 import javax.ws.rs.Produces; 27 import javax.ws.rs.Produces;
30 import javax.ws.rs.core.MediaType; 28 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response; 29 import javax.ws.rs.core.Response;
32 import java.io.InputStream; 30 import java.io.InputStream;
33 31
32 +/**
33 + * Handles REST API call of Neutron ML2 plugin.
34 + */
34 @Path("networks") 35 @Path("networks")
35 public class OpenstackNetworkWebResource extends AbstractWebResource { 36 public class OpenstackNetworkWebResource extends AbstractWebResource {
36 37
37 protected static final Logger log = LoggerFactory 38 protected static final Logger log = LoggerFactory
38 .getLogger(OpenstackNetworkWebResource.class); 39 .getLogger(OpenstackNetworkWebResource.class);
39 40
40 - private static final OpenstackNetworkCodec NETWORK_CODEC = new OpenstackNetworkCodec();
41 -
42 @POST 41 @POST
43 @Consumes(MediaType.APPLICATION_JSON) 42 @Consumes(MediaType.APPLICATION_JSON)
44 @Produces(MediaType.APPLICATION_JSON) 43 @Produces(MediaType.APPLICATION_JSON)
45 public Response createNetwork(InputStream input) { 44 public Response createNetwork(InputStream input) {
46 - try { 45 + log.debug("REST API networks is called {}", input.toString());
47 - ObjectMapper mapper = new ObjectMapper(); 46 + return Response.status(Response.Status.OK).build();
48 - ObjectNode networkNode = (ObjectNode) mapper.readTree(input); 47 + }
49 48
50 - OpenstackNetwork openstackNetwork = NETWORK_CODEC.decode(networkNode, this); 49 + @PUT
50 + @Path("{id}")
51 + @Consumes(MediaType.APPLICATION_JSON)
52 + @Produces(MediaType.APPLICATION_JSON)
53 + public Response updateNetwork(InputStream input) {
54 + log.debug("REST API networks is called {}", input.toString());
55 + return Response.status(Response.Status.OK).build();
56 + }
51 57
52 - OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class); 58 + @DELETE
53 - switchingService.createNetwork(openstackNetwork); 59 + @Path("{id}")
54 - return Response.status(Response.Status.OK).build(); 60 + @Consumes(MediaType.APPLICATION_JSON)
55 - } catch (Exception e) { 61 + @Produces(MediaType.APPLICATION_JSON)
56 - log.error("Creates VirtualPort failed because of exception {}", 62 + public Response deleteNetwork(InputStream input) {
57 - e.toString()); 63 + log.debug("REST API networks is called {}", input.toString());
58 - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) 64 + return Response.status(Response.Status.OK).build();
59 - .build();
60 - }
61 } 65 }
62 } 66 }
......
...@@ -58,6 +58,9 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> { ...@@ -58,6 +58,9 @@ public class OpenstackPortCodec extends JsonCodec<OpenstackPort> {
58 58
59 HashMap<String, Ip4Address> fixedIpMap = new HashMap<>(); 59 HashMap<String, Ip4Address> fixedIpMap = new HashMap<>();
60 JsonNode portInfo = json.get(PORT); 60 JsonNode portInfo = json.get(PORT);
61 + if (portInfo == null) {
62 + portInfo = json;
63 + }
61 64
62 String status = portInfo.path(STATUS).asText(); 65 String status = portInfo.path(STATUS).asText();
63 String name = portInfo.path(NAME).asText(); 66 String name = portInfo.path(NAME).asText();
......
...@@ -33,6 +33,9 @@ import javax.ws.rs.core.MediaType; ...@@ -33,6 +33,9 @@ import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response; 33 import javax.ws.rs.core.Response;
34 import java.io.InputStream; 34 import java.io.InputStream;
35 35
36 +/**
37 + * Handles Rest API call from Neutron ML2 plugin.
38 + */
36 @Path("ports") 39 @Path("ports")
37 public class OpenstackPortWebResource extends AbstractWebResource { 40 public class OpenstackPortWebResource extends AbstractWebResource {
38 41
...@@ -50,13 +53,15 @@ public class OpenstackPortWebResource extends AbstractWebResource { ...@@ -50,13 +53,15 @@ public class OpenstackPortWebResource extends AbstractWebResource {
50 ObjectNode portNode = (ObjectNode) mapper.readTree(input); 53 ObjectNode portNode = (ObjectNode) mapper.readTree(input);
51 54
52 OpenstackPort openstackPort = PORT_CODEC.decode(portNode, this); 55 OpenstackPort openstackPort = PORT_CODEC.decode(portNode, this);
53 - 56 + OpenstackSwitchingService switchingService =
54 - OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class); 57 + getService(OpenstackSwitchingService.class);
55 switchingService.createPorts(openstackPort); 58 switchingService.createPorts(openstackPort);
59 +
56 log.debug("REST API ports is called with {}", portNode.toString()); 60 log.debug("REST API ports is called with {}", portNode.toString());
57 return Response.status(Response.Status.OK).build(); 61 return Response.status(Response.Status.OK).build();
62 +
58 } catch (Exception e) { 63 } catch (Exception e) {
59 - log.error("Creates VirtualPort failed because of exception {}", 64 + log.error("Creates Port failed because of exception {}",
60 e.toString()); 65 e.toString());
61 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) 66 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
62 .build(); 67 .build();
...@@ -64,23 +69,12 @@ public class OpenstackPortWebResource extends AbstractWebResource { ...@@ -64,23 +69,12 @@ public class OpenstackPortWebResource extends AbstractWebResource {
64 } 69 }
65 70
66 @DELETE 71 @DELETE
72 + @Path("{id}")
67 @Consumes(MediaType.APPLICATION_JSON) 73 @Consumes(MediaType.APPLICATION_JSON)
68 @Produces(MediaType.APPLICATION_JSON) 74 @Produces(MediaType.APPLICATION_JSON)
69 public Response deletesPorts(InputStream input) { 75 public Response deletesPorts(InputStream input) {
70 - try { 76 + log.debug("REST API ports is called with {}", input.toString());
71 - ObjectMapper mapper = new ObjectMapper(); 77 + return Response.status(Response.Status.OK).build();
72 - ObjectNode portNode = (ObjectNode) mapper.readTree(input);
73 -
74 - OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class);
75 - switchingService.deletePorts();
76 - log.info("REST API ports is called with {}", portNode.toString());
77 - return Response.status(Response.Status.OK).build();
78 - } catch (Exception e) {
79 - log.error("Delete VirtualPort failed because of exception {}",
80 - e.toString());
81 - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
82 - .build();
83 - }
84 } 78 }
85 79
86 @PUT 80 @PUT
...@@ -88,19 +82,7 @@ public class OpenstackPortWebResource extends AbstractWebResource { ...@@ -88,19 +82,7 @@ public class OpenstackPortWebResource extends AbstractWebResource {
88 @Consumes(MediaType.APPLICATION_JSON) 82 @Consumes(MediaType.APPLICATION_JSON)
89 @Produces(MediaType.APPLICATION_JSON) 83 @Produces(MediaType.APPLICATION_JSON)
90 public Response updatePorts(InputStream input) { 84 public Response updatePorts(InputStream input) {
91 - try { 85 + log.info("REST API ports is called with {}", input.toString());
92 - ObjectMapper mapper = new ObjectMapper(); 86 + return Response.status(Response.Status.OK).build();
93 - ObjectNode portNode = (ObjectNode) mapper.readTree(input);
94 -
95 - OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class);
96 - switchingService.updatePorts();
97 - log.info("REST API ports is called with {}", portNode.toString());
98 - return Response.status(Response.Status.OK).build();
99 - } catch (Exception e) {
100 - log.error("Update VirtualPort failed because of exception {}",
101 - e.toString());
102 - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
103 - .build();
104 - }
105 } 87 }
106 } 88 }
......
...@@ -51,6 +51,9 @@ public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> { ...@@ -51,6 +51,9 @@ public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> {
51 @Override 51 @Override
52 public OpenstackSubnet decode(ObjectNode json, CodecContext context) { 52 public OpenstackSubnet decode(ObjectNode json, CodecContext context) {
53 JsonNode subnetInfo = json.get(SUBNET); 53 JsonNode subnetInfo = json.get(SUBNET);
54 + if (subnetInfo == null) {
55 + subnetInfo = json;
56 + }
54 57
55 String name = subnetInfo.path(NAME).asText(); 58 String name = subnetInfo.path(NAME).asText();
56 boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean(); 59 boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean();
......
...@@ -15,18 +15,19 @@ ...@@ -15,18 +15,19 @@
15 */ 15 */
16 package org.onosproject.openstackswitching.web; 16 package org.onosproject.openstackswitching.web;
17 17
18 - 18 +/**
19 -import com.fasterxml.jackson.databind.ObjectMapper; 19 + * Handles Rest API call from Neutron ML2 plugin.
20 -import com.fasterxml.jackson.databind.node.ObjectNode; 20 + */
21 -import org.onosproject.openstackswitching.OpenstackSubnet;
22 -import org.onosproject.openstackswitching.OpenstackSwitchingService;
23 import org.onosproject.rest.AbstractWebResource; 21 import org.onosproject.rest.AbstractWebResource;
24 import org.slf4j.Logger; 22 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
26 24
27 import javax.ws.rs.Consumes; 25 import javax.ws.rs.Consumes;
26 +import javax.ws.rs.DELETE;
28 import javax.ws.rs.POST; 27 import javax.ws.rs.POST;
28 +import javax.ws.rs.PUT;
29 import javax.ws.rs.Path; 29 import javax.ws.rs.Path;
30 +import javax.ws.rs.PathParam;
30 import javax.ws.rs.Produces; 31 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.MediaType; 32 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.Response; 33 import javax.ws.rs.core.Response;
...@@ -37,28 +38,32 @@ public class OpenstackSubnetWebResource extends AbstractWebResource { ...@@ -37,28 +38,32 @@ public class OpenstackSubnetWebResource extends AbstractWebResource {
37 protected static final Logger log = LoggerFactory 38 protected static final Logger log = LoggerFactory
38 .getLogger(OpenstackSubnetWebResource.class); 39 .getLogger(OpenstackSubnetWebResource.class);
39 40
40 - private static final OpenstackSubnetCodec SUBNET_CODEC = new OpenstackSubnetCodec();
41 -
42 @POST 41 @POST
43 @Consumes(MediaType.APPLICATION_JSON) 42 @Consumes(MediaType.APPLICATION_JSON)
44 @Produces(MediaType.APPLICATION_JSON) 43 @Produces(MediaType.APPLICATION_JSON)
45 public Response createSubnet(InputStream input) { 44 public Response createSubnet(InputStream input) {
46 - try { 45 + return Response.status(Response.Status.OK).build();
47 - ObjectMapper mapper = new ObjectMapper(); 46 + }
48 - ObjectNode subnetNode = (ObjectNode) mapper.readTree(input); 47 +
48 +
49 + @PUT
50 + @Path("{subnetUUID}")
51 + @Produces(MediaType.APPLICATION_JSON)
52 + @Consumes(MediaType.APPLICATION_JSON)
53 + public Response updateSubnet(@PathParam("id") String id,
54 + final InputStream input) {
55 + return Response.status(Response.Status.OK).build();
49 56
50 - OpenstackSubnet openstackSubnet = SUBNET_CODEC.decode(subnetNode, this); 57 + }
51 58
52 - OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class); 59 + @DELETE
53 - switchingService.createSubnet(openstackSubnet); 60 + @Path("{subnetUUID}")
54 - log.debug("REST API subnets is called with {}", subnetNode.toString()); 61 + @Produces(MediaType.APPLICATION_JSON)
55 - return Response.status(Response.Status.OK).build(); 62 + @Consumes(MediaType.APPLICATION_JSON)
56 - } catch (Exception e) { 63 + public Response deleteSubnet(@PathParam("id") String id,
57 - log.error("Creates VirtualSubnet failed because of exception {}", 64 + final InputStream input) {
58 - e.toString()); 65 + return Response.status(Response.Status.OK).build();
59 - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString())
60 - .build();
61 - }
62 } 66 }
63 67
68 +
64 } 69 }
......
1 +{
2 + "apps" : {
3 + "org.onosproject.openstackswitching" : {
4 + "openstackswitching" : {
5 + "do_not_push_flows" : "false",
6 + "neutron_server" : "http://127.0.0.1:9696/v2.0/",
7 + "keystone_server" : "http://127.0.0.1:5000/v2.0/",
8 + "user_name" : "admin",
9 + "password" : "nova"
10 + }
11 + },
12 + "org.onosproject.dhcp" : {
13 + "dhcp" : {
14 + "ip": "10.0.0.1",
15 + "mac": "1a:2b:3c:4e:5e:6f",
16 + "subnet": "255.0.0.0",
17 + "broadcast": "10.255.255.255",
18 + "router": "10.0.0.1",
19 + "domain": "10.0.0.1",
20 + "ttl": "63",
21 + "lease": "300",
22 + "renew": "150",
23 + "rebind": "200",
24 + "delay": "3",
25 + "timeout": "150",
26 + "startip": "10.0.0.110",
27 + "endip": "10.0.0.130"
28 + }
29 + },
30 + "org.onosproject.cordvtn" : {
31 + "cordvtn" : {
32 + "ovsdbNodes" : [
33 + {
34 + "host" : "compute-01",
35 + "ip" : "128.199.162.106",
36 + "port" : "6640",
37 + "bridgeId" : "of:0000000000000001"
38 + },
39 + {
40 + "host" : "compute-02",
41 + "ip" : "103.253.145.133",
42 + "port" : "6640",
43 + "bridgeId" : "of:0000000000000002"
44 + },
45 + {
46 + "host" : "network",
47 + "ip" : "128.199.125.11",
48 + "port" : "6640",
49 + "bridgeId" : "of:0000000000000003"
50 + }
51 + ]
52 + }
53 + }
54 + }
55 +}