import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
-import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
-import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
+import javax.xml.bind.JAXBElement;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
return hostTracker;
}
+ private Hosts convertHosts(Set<HostNodeConnector> hostNodeConnectors) {
+ if(hostNodeConnectors == null) {
+ return null;
+ }
+ Set<HostConfig> hosts = new HashSet<HostConfig>();
+ for(HostNodeConnector hnc : hostNodeConnectors) {
+ hosts.add(HostConfig.convert(hnc));
+ }
+ return new Hosts(hosts);
+ }
+
/**
* Returns a list of all Hosts : both configured via PUT API and dynamically
* learnt on the network.
* Name of the Container. The Container name for the base
* controller is "default".
* @return List of Active Hosts.
+ * <pre>
+ *
+ * Example:
+ *
+ * RequestURL:
+ *
+ * http://localhost:8080/controller/nb/v2/host/default
+ *
+ * Response in XML
+ *
+ * <list>
+ *  <hostConfig>
+ *   <dataLayerAddress>00:00:00:00:01:01</dataLayerAddress>
+ *   <networkAddress>1.1.1.1</networkAddress>
+ *   <nodeType>OF</nodeType>
+ *   <nodeId>00:00:00:00:00:00:00:01</nodeId>
+ *   <nodeConnectorType>OF</nodeConnectorType>
+ *   <nodeConnectorId>9</nodeConnectorId>
+ *   <vlan>0</vlan>
+ *   <staticHost>false</staticHost>
+ *  </hostConfig>
+ *  <hostConfig>
+ *   <dataLayerAddress>00:00:00:00:02:02</dataLayerAddress>
+ *   <networkAddress>2.2.2.2</networkAddress>
+ *   <nodeType>OF</nodeType>
+ *   <nodeId>00:00:00:00:00:00:00:02</nodeId>
+ *   <nodeConnectorType>OF</nodeConnectorType>
+ *   <nodeConnectorId>5</nodeConnectorId>
+ *   <vlan>0</vlan>
+ *   <staticHost>false</staticHost>
+ *  </hostConfig>
+ * </list>
+ *
+ * Response in JSON:
+ *
+ * {
+ *  "hostConfig":[
+ *   {
+ *    "dataLayerAddress":"00:00:00:00:01:01",
+ *    "nodeType":"OF",
+ *    "nodeId":"00:00:00:00:00:00:00:01",
+ *    "nodeConnectorType":"OF",
+ *    "nodeConnectorId":"9",
+ *    "vlan":"0",
+ *    "staticHost":"false",
+ *    "networkAddress":"1.1.1.1"
+ *   },
+ *   {
+ *    "dataLayerAddress":"00:00:00:00:02:02",
+ *    "nodeType":"OF",
+ *    "nodeId":"00:00:00:00:00:00:00:02",
+ *    "nodeConnectorType":"OF",
+ *    "nodeConnectorId":"5",
+ *    "vlan":"0",
+ *    "staticHost":"false",
+ *    "networkAddress":"2.2.2.2"
+ *   }
+ *  ]
+ * }
+ * </pre>
*/
@Path("/{containerName}")
@GET
throw new ServiceUnavailableException("Host Tracker "
+ RestMessages.SERVICEUNAVAILABLE.toString());
}
-
- return new Hosts(hostTracker.getAllHosts());
+ return convertHosts(hostTracker.getAllHosts());
}
/**
* Name of the Container. The Container name for the base
* controller is "default".
* @return List of inactive Hosts.
+ * <pre>
+ *
+ * Example:
+ *
+ * RequestURL:
+ *
+ * http://localhost:8080/controller/nb/v2/host/default/inactive
+ *
+ * Response in XML
+ *
+ * <list>
+ *  <hostConfig>
+ *   <dataLayerAddress>00:00:00:00:01:01</dataLayerAddress>
+ *   <networkAddress>1.1.1.1</networkAddress>
+ *   <nodeType>OF</nodeType>
+ *   <nodeId>00:00:00:00:00:00:00:01</nodeId>
+ *   <nodeConnectorType>OF</nodeConnectorType>
+ *   <nodeConnectorId>9</nodeConnectorId>
+ *   <vlan>0</vlan>
+ *   <staticHost>false</staticHost>
+ *  </hostConfig>
+ *  <hostConfig>
+ *   <dataLayerAddress>00:00:00:00:02:02</dataLayerAddress>
+ *   <networkAddress>2.2.2.2</networkAddress>
+ *   <nodeType>OF</nodeType>
+ *   <nodeId>00:00:00:00:00:00:00:02</nodeId>
+ *   <nodeConnectorType>OF</nodeConnectorType>
+ *   <nodeConnectorId>5</nodeConnectorId>
+ *   <vlan>0</vlan>
+ *   <staticHost>false</staticHost>
+ *  </hostConfig>
+ * </list>
+ *
+ * Response in JSON:
+ *
+ * {
+ *  "hostConfig":[
+ *   {
+ *    "dataLayerAddress":"00:00:00:00:01:01",
+ *    "nodeType":"OF",
+ *    "nodeId":"00:00:00:00:00:00:00:01",
+ *    "nodeConnectorType":"OF",
+ *    "nodeConnectorId":"9",
+ *    "vlan":"0",
+ *    "staticHost":"false",
+ *    "networkAddress":"1.1.1.1"
+ *   },
+ *   {
+ *    "dataLayerAddress":"00:00:00:00:02:02",
+ *    "nodeType":"OF",
+ *    "nodeId":"00:00:00:00:00:00:00:02",
+ *    "nodeConnectorType":"OF",
+ *    "nodeConnectorId":"5",
+ *    "vlan":"0",
+ *    "staticHost":"false",
+ *    "networkAddress":"2.2.2.2"
+ *   }
+ *  ]
+ * }
+ * </pre>
*/
@Path("/{containerName}/inactive")
@GET
throw new ServiceUnavailableException("Host Tracker "
+ RestMessages.SERVICEUNAVAILABLE.toString());
}
-
- return new Hosts(hostTracker.getInactiveStaticHosts());
+ return convertHosts(hostTracker.getInactiveStaticHosts());
}
/**
* @param networkAddress
* IP Address being looked up
* @return host that matches the IP Address
+ * <pre>
+ *
+ * Example:
+ *
+ * RequestURL:
+ *
+ * http://localhost:8080/controller/nb/v2/host/default/1.1.1.1
+ *
+ * Response in XML
+ *
+ * <hostConfig>
+ *  <dataLayerAddress>00:00:00:00:01:01</dataLayerAddress>
+ *  <networkAddress>1.1.1.1</networkAddress>
+ *  <nodeType>OF</nodeType>
+ *  <nodeId>00:00:00:00:00:00:00:01</nodeId>
+ *  <nodeConnectorType>OF</nodeConnectorType>
+ *  <nodeConnectorId>9</nodeConnectorId>
+ *  <vlan>0</vlan>
+ *  <staticHost>false</staticHost>
+ * </hostConfig>
+ *
+ * Response in JSON:
+ *
+ * {
+ *  "dataLayerAddress":"00:00:00:00:01:01",
+ *  "nodeType":"OF",
+ *  "nodeId":"00:00:00:00:00:00:00:01",
+ *  "nodeConnectorType":"OF",
+ *  "nodeConnectorId":"9",
+ *  "vlan":"0",
+ *  "staticHost":"false",
+ *  "networkAddress":"1.1.1.1"
+ * }
+ * </pre>
*/
@Path("/{containerName}/{networkAddress}")
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
- @TypeHint(HostNodeConnector.class)
+ @TypeHint(HostConfig.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "Operation successful"),
@ResponseCode(code = 404, condition = "The containerName is not found"),
@ResponseCode(code = 415, condition = "Invalid IP Address passed in networkAddress parameter"),
@ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
- public HostNodeConnector getHostDetails(
+ public HostConfig getHostDetails(
@PathParam("containerName") String containerName,
@PathParam("networkAddress") String networkAddress) {
if (!NorthboundUtils.isAuthorized(
}
for (HostNodeConnector host : hostTracker.getAllHosts()) {
if (host.getNetworkAddress().equals(ip)) {
- return host;
+ return HostConfig.convert(host);
}
}
throw new ResourceNotFoundException(RestMessages.NOHOST.toString());
* controller is "default".
* @param networkAddress
* Host IP Address
- * @param dataLayerAddress
- * Host L2 data-layer address.
- * @param nodeType
- * Node Type as specifid by Node class
- * @param nodeId
- * Node Identifier as specifid by Node class
- * @param nodeConnectorType
- * Port Type as specified by NodeConnector class
- * @param nodeConnectorId
- * Port Identifier as specified by NodeConnector class
- * @param vlan
- * Vlan number
+ * @param hostConfig
+ * Host Config Details
* @return Response as dictated by the HTTP Response Status code
+ *
+ * <pre>
+ *
+ * Example:
+ *
+ * RequestURL:
+ *
+ * http://localhost:8080/controller/nb/v2/host/default/1.1.1.1
+ *
+ * Request in XML
+ *
+ * <hostConfig>
+ *  <dataLayerAddress>00:00:00:00:01:01</dataLayerAddress>
+ *  <networkAddress>1.1.1.1</networkAddress>
+ *  <nodeType>OF</nodeType>
+ *  <nodeId>00:00:00:00:00:00:00:01</nodeId>
+ *  <nodeConnectorType>OF</nodeConnectorType>
+ *  <nodeConnectorId>9</nodeConnectorId>
+ *  <vlan>0</vlan>
+ *  <staticHost>false</staticHost>
+ * </hostConfig>
+ *
+ * Request in JSON:
+ *
+ * {
+ *  "dataLayerAddress":"00:00:00:00:01:01",
+ *  "nodeType":"OF",
+ *  "nodeId":"00:00:00:00:00:00:00:01",
+ *  "nodeConnectorType":"OF",
+ *  "nodeConnectorId":"9",
+ *  "vlan":"0",
+ *  "staticHost":"false",
+ *  "networkAddress":"1.1.1.1"
+ * }
+ * </pre>
*/
@Path("/{containerName}/{networkAddress}")
- @POST
+ @PUT
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@StatusCodes({
@ResponseCode(code = 201, condition = "Static host created successfully"),
@ResponseCode(code = 503, condition = "One or more of Controller services are unavailable") })
public Response addHost(@PathParam("containerName") String containerName,
@PathParam("networkAddress") String networkAddress,
- @QueryParam("dataLayerAddress") String dataLayerAddress,
- @QueryParam("nodeType") String nodeType,
- @QueryParam("nodeId") String nodeId,
- @QueryParam("nodeConnectorType") String nodeConnectorType,
- @QueryParam("nodeConnectorId") String nodeConnectorId,
- @DefaultValue("0") @QueryParam("vlan") String vlan) {
+ @TypeHint(HostConfig.class) JAXBElement<HostConfig> hostConfig) {
if (!NorthboundUtils.isAuthorized(
getUserName(), containerName, Privilege.WRITE, this)) {
+ RestMessages.SERVICEUNAVAILABLE.toString());
}
- Node node = handleNodeAvailability(containerName, nodeType, nodeId);
+ HostConfig hc = hostConfig.getValue();
+ Node node = handleNodeAvailability(containerName, hc.getNodeType(), hc.getNodeId());
if (node == null) {
throw new InternalServerErrorException(
RestMessages.NONODE.toString());
throw new UnsupportedMediaTypeException(networkAddress + " "
+ RestMessages.INVALIDADDRESS.toString());
}
- NodeConnector nc = NodeConnector.fromStringNoNode(nodeConnectorType,
- nodeConnectorId, node);
+ if(!networkAddress.equals(hc.getNetworkAddress())) {
+ throw new UnsupportedMediaTypeException(networkAddress + " is not the same as "
+ + hc.getNetworkAddress());
+ }
+ if(!hc.isStaticHost()) {
+ throw new UnsupportedMediaTypeException("StaticHost flag must be true");
+ }
+ NodeConnector nc = NodeConnector.fromStringNoNode(hc.getNodeConnectorType(), hc.getNodeConnectorId(), node);
if (nc == null) {
- throw new ResourceNotFoundException(nodeConnectorType + "|"
- + nodeConnectorId + " : " + RestMessages.NONODE.toString());
+ throw new ResourceNotFoundException(hc.getNodeConnectorType() + "|"
+ + hc.getNodeConnectorId() + " : " + RestMessages.NONODE.toString());
}
Status status = hostTracker.addStaticHost(networkAddress,
- dataLayerAddress, nc, vlan);
+ hc.getDataLayerAddress(), nc, hc.getVlan());
if (status.isSuccess()) {
NorthboundUtils.auditlog("Static Host", username, "added", networkAddress, containerName);
return Response.status(Response.Status.CREATED).build();