Added the missing Copyright headers to most of the java files.
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / PortHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
3  *
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
7  *
8  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10 package org.opendaylight.ovsdb.neutron;
11
12 import java.net.HttpURLConnection;
13
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;
18
19 /**
20  * Handle requests for Neutron Port.
21  */
22 public class PortHandler extends BaseHandler
23                          implements INeutronPortAware {
24
25     /**
26      * Logger instance.
27      */
28     static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
29
30     /**
31      * Invoked when a port creation is requested
32      * to indicate if the specified port can be created.
33      *
34      * @param port     An instance of proposed new Port Port object.
35      * @return A HTTP status code to the creation request.
36      */
37     @Override
38     public int canCreatePort(NeutronPort port) {
39         return HttpURLConnection.HTTP_CREATED;
40     }
41
42     /**
43      * Invoked to take action after a port has been created.
44      *
45      * @param port An instance of new Neutron Port object.
46      */
47     @Override
48     public void neutronPortCreated(NeutronPort port) {
49
50         int result = canCreatePort(port);
51         if (result != HttpURLConnection.HTTP_CREATED) {
52             logger.error(" Port create validation failed result - {} ", result);
53             return;
54         }
55
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();
61
62         // Create Full Mesh Tunnels
63         /*
64          * Is this required ?
65          * The Tunnel Creation logic is completely owned by the Southbound handler at this point.
66
67         NeutronNetwork network = this.neutronNetworkCache.getNetwork(port.getNetworkUUID());
68         ProviderNetworkManager.getManager().createTunnels(network.getProviderNetworkType(),
69                                                           network.getProviderSegmentationID());
70          */
71         logger.debug(" Port-ADD successful for tenant-id - {}," +
72                 " network-id - {}, port-id - {}, result - {} ",
73                 tenantID, networkID, portID, result);
74     }
75
76     /**
77      * Invoked when a port update is requested
78      * to indicate if the specified port can be changed
79      * using the specified delta.
80      *
81      * @param delta    Updates to the port object using patch semantics.
82      * @param original An instance of the Neutron Port object
83      *                  to be updated.
84      * @return A HTTP status code to the update request.
85      */
86     @Override
87     public int canUpdatePort(NeutronPort delta,
88                              NeutronPort original) {
89         int result = HttpURLConnection.HTTP_OK;
90         /**
91          * To basic validation of the request
92          */
93
94         if ((original == null) || (delta == null)) {
95             logger.error("port object not specified");
96             return HttpURLConnection.HTTP_BAD_REQUEST;
97         }
98         return result;
99     }
100
101     /**
102      * Invoked to take action after a port has been updated.
103      *
104      * @param port An instance of modified Neutron Port object.
105      */
106     @Override
107     public void neutronPortUpdated(NeutronPort port) {
108     }
109
110     /**
111      * Invoked when a port deletion is requested
112      * to indicate if the specified port can be deleted.
113      *
114      * @param port     An instance of the Neutron Port object to be deleted.
115      * @return A HTTP status code to the deletion request.
116      */
117     @Override
118     public int canDeletePort(NeutronPort port) {
119         int result = HttpURLConnection.HTTP_OK;
120         return result;
121     }
122
123     /**
124      * Invoked to take action after a port has been deleted.
125      *
126      * @param port  An instance of deleted Neutron Port object.
127      */
128     @Override
129     public void neutronPortDeleted(NeutronPort port) {
130
131         int result = canDeletePort(port);
132         if  (result != HttpURLConnection.HTTP_OK) {
133             logger.error(" deletePort validation failed - result {} ", result);
134             return;
135         }
136
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);
142
143     }
144 }