1 package org.opendaylight.ovsdb.neutron;
3 import java.net.HttpURLConnection;
5 import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
6 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
11 * Handle requests for Neutron Port.
13 public class PortHandler extends BaseHandler
14 implements INeutronPortAware {
19 static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
22 * Invoked when a port creation is requested
23 * to indicate if the specified port can be created.
25 * @param port An instance of proposed new Port Port object.
26 * @return A HTTP status code to the creation request.
29 public int canCreatePort(NeutronPort port) {
30 return HttpURLConnection.HTTP_CREATED;
34 * Invoked to take action after a port has been created.
36 * @param port An instance of new Neutron Port object.
39 public void neutronPortCreated(NeutronPort port) {
41 int result = canCreatePort(port);
42 if (result != HttpURLConnection.HTTP_CREATED) {
43 logger.error(" Port create validation failed result - {} ", result);
47 String tenantID = convertNeutronIDToKey(port.getTenantID());
48 String networkID = convertNeutronIDToKey(port.getNetworkUUID());
49 String portID = convertNeutronIDToKey(port.getID());
50 String portDesc = port.getName();
51 Boolean portAdminState = port.getAdminStateUp();
53 // Create Full Mesh Tunnels
56 * The Tunnel Creation logic is completely owned by the Southbound handler at this point.
58 NeutronNetwork network = this.neutronNetworkCache.getNetwork(port.getNetworkUUID());
59 ProviderNetworkManager.getManager().createTunnels(network.getProviderNetworkType(),
60 network.getProviderSegmentationID());
62 logger.debug(" Port-ADD successful for tenant-id - {}," +
63 " network-id - {}, port-id - {}, result - {} ",
64 tenantID, networkID, portID, result);
68 * Invoked when a port update is requested
69 * to indicate if the specified port can be changed
70 * using the specified delta.
72 * @param delta Updates to the port object using patch semantics.
73 * @param original An instance of the Neutron Port object
75 * @return A HTTP status code to the update request.
78 public int canUpdatePort(NeutronPort delta,
79 NeutronPort original) {
80 int result = HttpURLConnection.HTTP_OK;
82 * To basic validation of the request
85 if ((original == null) || (delta == null)) {
86 logger.error("port object not specified");
87 return HttpURLConnection.HTTP_BAD_REQUEST;
93 * Invoked to take action after a port has been updated.
95 * @param port An instance of modified Neutron Port object.
98 public void neutronPortUpdated(NeutronPort port) {
102 * Invoked when a port deletion is requested
103 * to indicate if the specified port can be deleted.
105 * @param port An instance of the Neutron Port object to be deleted.
106 * @return A HTTP status code to the deletion request.
109 public int canDeletePort(NeutronPort port) {
110 int result = HttpURLConnection.HTTP_OK;
115 * Invoked to take action after a port has been deleted.
117 * @param port An instance of deleted Neutron Port object.
120 public void neutronPortDeleted(NeutronPort port) {
122 int result = canDeletePort(port);
123 if (result != HttpURLConnection.HTTP_OK) {
124 logger.error(" deletePort validation failed - result {} ", result);
128 String tenantID = convertNeutronIDToKey(port.getTenantID());
129 String networkID = convertNeutronIDToKey(port.getNetworkUUID());
130 String portID = convertNeutronIDToKey(port.getID());
131 logger.debug(" PORT delete successful for tenant-id - {}, " +
132 " network-id - {}, port-id - {}", tenantID, networkID, portID);