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 * Add the Corresponding OF NodeConnector to the Container
55 ContainerConfig config = new ContainerConfig();
56 config.setContainer(networkID);
57 logger.debug("Adding Port {} to Container : {}", port.toString(), config.getContainer());
58 List<String> ncList = new ArrayList<String>();
59 ncList.add("OVS|"+ portID +"@OVS|"+networkID);
60 config.addNodeConnectors(ncList);
61 Status status = containerManager.addContainerEntry(networkID, ncList);
63 if (!status.isSuccess()) {
64 logger.error(" Port-ADD failed for tenant-id - {}," +
65 " bridge-id - {}, port-id - {}, result - {} ",
66 tenantID, networkID, portID, result);
68 logger.debug(" Port-ADD successful for tenant-id - {}," +
69 " bridge-id - {}, port-id - {}, result - {} ",
70 tenantID, networkID, portID, result);
73 logger.debug(" Port-ADD successful for tenant-id - {}," +
74 " network-id - {}, port-id - {}, result - {} ",
75 tenantID, networkID, portID, result);
79 * Invoked when a port update is requested
80 * to indicate if the specified port can be changed
81 * using the specified delta.
83 * @param delta Updates to the port object using patch semantics.
84 * @param original An instance of the Neutron Port object
86 * @return A HTTP status code to the update request.
89 public int canUpdatePort(NeutronPort delta,
90 NeutronPort original) {
91 int result = HttpURLConnection.HTTP_OK;
93 * To basic validation of the request
96 if ((original == null) || (delta == null)) {
97 logger.error("port object not specified");
98 return HttpURLConnection.HTTP_BAD_REQUEST;
104 * Invoked to take action after a port has been updated.
106 * @param port An instance of modified Neutron Port object.
109 public void neutronPortUpdated(NeutronPort port) {
113 * Invoked when a port deletion is requested
114 * to indicate if the specified port can be deleted.
116 * @param port An instance of the Neutron Port object to be deleted.
117 * @return A HTTP status code to the deletion request.
120 public int canDeletePort(NeutronPort port) {
121 int result = HttpURLConnection.HTTP_OK;
126 * Invoked to take action after a port has been deleted.
128 * @param port An instance of deleted Neutron Port object.
131 public void neutronPortDeleted(NeutronPort port) {
133 int result = canDeletePort(port);
134 if (result != HttpURLConnection.HTTP_OK) {
135 logger.error(" deletePort validation failed - result {} ", result);
139 String tenantID = convertNeutronIDToKey(port.getTenantID());
140 String networkID = convertNeutronIDToKey(port.getNetworkUUID());
141 String portID = convertNeutronIDToKey(port.getID());
143 * Delete the Corresponding OF NodeConnector from the Container
145 ContainerConfig config = new ContainerConfig();
146 config.setContainer(networkID);
147 List<String> ncList = new ArrayList<String>();
148 ncList.add("OVS|"+ portID +"@OVS|"+networkID);
149 config.addNodeConnectors(ncList);
150 Status status = containerManager.removeContainerEntry(networkID, ncList);
151 if (!status.isSuccess()) {
152 logger.error(" PORT delete failed for tenant-id - {}, " +
153 " bridge-id - {}, port-id - {}, result - {} ",
154 tenantID, networkID, portID, status);
156 logger.error(" PORT delete successful for tenant-id - {}, " +
157 " bridge-id - {}, port-id - {}, result - {} ",
158 tenantID, networkID, portID, status);
161 logger.debug(" PORT delete successful for tenant-id - {}, " +
162 " network-id - {}, port-id - {}", tenantID, networkID, portID);