2 * Copyright (C) 2013 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal, Brent Salisbury
10 package org.opendaylight.ovsdb.neutron;
12 import java.net.HttpURLConnection;
14 import org.opendaylight.controller.networkconfig.neutron.INeutronPortAware;
15 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Handle requests for Neutron Port.
22 public class PortHandler extends BaseHandler
23 implements INeutronPortAware {
28 static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
31 * Invoked when a port creation is requested
32 * to indicate if the specified port can be created.
34 * @param port An instance of proposed new Port Port object.
35 * @return A HTTP status code to the creation request.
38 public int canCreatePort(NeutronPort port) {
39 return HttpURLConnection.HTTP_CREATED;
43 * Invoked to take action after a port has been created.
45 * @param port An instance of new Neutron Port object.
48 public void neutronPortCreated(NeutronPort port) {
50 int result = canCreatePort(port);
51 if (result != HttpURLConnection.HTTP_CREATED) {
52 logger.error(" Port create validation failed result - {} ", result);
56 String tenantID = convertNeutronIDToKey(port.getTenantID());
57 String networkID = convertNeutronIDToKey(port.getNetworkUUID());
58 String portID = convertNeutronIDToKey(port.getID());
59 String portDesc = port.getName();
60 Boolean portAdminState = port.getAdminStateUp();
62 // Create Full Mesh Tunnels
65 * The Tunnel Creation logic is completely owned by the Southbound handler at this point.
67 NeutronNetwork network = this.neutronNetworkCache.getNetwork(port.getNetworkUUID());
68 ProviderNetworkManager.getManager().createTunnels(network.getProviderNetworkType(),
69 network.getProviderSegmentationID());
71 logger.debug(" Port-ADD successful for tenant-id - {}," +
72 " network-id - {}, port-id - {}, result - {} ",
73 tenantID, networkID, portID, result);
77 * Invoked when a port update is requested
78 * to indicate if the specified port can be changed
79 * using the specified delta.
81 * @param delta Updates to the port object using patch semantics.
82 * @param original An instance of the Neutron Port object
84 * @return A HTTP status code to the update request.
87 public int canUpdatePort(NeutronPort delta,
88 NeutronPort original) {
89 int result = HttpURLConnection.HTTP_OK;
91 * To basic validation of the request
94 if ((original == null) || (delta == null)) {
95 logger.error("port object not specified");
96 return HttpURLConnection.HTTP_BAD_REQUEST;
102 * Invoked to take action after a port has been updated.
104 * @param port An instance of modified Neutron Port object.
107 public void neutronPortUpdated(NeutronPort port) {
111 * Invoked when a port deletion is requested
112 * to indicate if the specified port can be deleted.
114 * @param port An instance of the Neutron Port object to be deleted.
115 * @return A HTTP status code to the deletion request.
118 public int canDeletePort(NeutronPort port) {
119 int result = HttpURLConnection.HTTP_OK;
124 * Invoked to take action after a port has been deleted.
126 * @param port An instance of deleted Neutron Port object.
129 public void neutronPortDeleted(NeutronPort port) {
131 int result = canDeletePort(port);
132 if (result != HttpURLConnection.HTTP_OK) {
133 logger.error(" deletePort validation failed - result {} ", result);
137 String tenantID = convertNeutronIDToKey(port.getTenantID());
138 String networkID = convertNeutronIDToKey(port.getNetworkUUID());
139 String portID = convertNeutronIDToKey(port.getID());
140 logger.debug(" PORT delete successful for tenant-id - {}, " +
141 " network-id - {}, port-id - {}", tenantID, networkID, portID);