Skeleton Event handlers for the Neutron integration with OVSDB.
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / PortHandler.java
1 package org.opendaylight.ovsdb.neutron;
2
3 import java.net.HttpURLConnection;
4
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;
9
10 /**
11  * Handle requests for Neutron Port.
12  */
13 public class PortHandler extends BaseHandler
14                          implements INeutronPortAware {
15
16     /**
17      * Logger instance.
18      */
19     static final Logger logger = LoggerFactory.getLogger(PortHandler.class);
20
21     /**
22      * Invoked when a port creation is requested
23      * to indicate if the specified port can be created.
24      *
25      * @param port     An instance of proposed new Port Port object.
26      * @return A HTTP status code to the creation request.
27      */
28     @Override
29     public int canCreatePort(NeutronPort port) {
30         return HttpURLConnection.HTTP_CREATED;
31     }
32
33     /**
34      * Invoked to take action after a port has been created.
35      *
36      * @param port An instance of new Neutron Port object.
37      */
38     @Override
39     public void neutronPortCreated(NeutronPort port) {
40
41         int result = canCreatePort(port);
42         if (result != HttpURLConnection.HTTP_CREATED) {
43             logger.error(" Port create validation failed result - {} ", result);
44             return;
45         }
46
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();
52 /*
53  * Add the Corresponding OF NodeConnector to the Container
54  *
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);
62
63         if (!status.isSuccess()) {
64             logger.error(" Port-ADD failed for tenant-id - {}," +
65                     " bridge-id - {}, port-id - {}, result - {} ",
66                     tenantID, networkID, portID, result);
67         } else {
68             logger.debug(" Port-ADD successful for tenant-id - {}," +
69                     " bridge-id - {}, port-id - {}, result - {} ",
70                     tenantID, networkID, portID, result);
71         }
72 */
73         logger.debug(" Port-ADD successful for tenant-id - {}," +
74                 " network-id - {}, port-id - {}, result - {} ",
75                 tenantID, networkID, portID, result);
76     }
77
78     /**
79      * Invoked when a port update is requested
80      * to indicate if the specified port can be changed
81      * using the specified delta.
82      *
83      * @param delta    Updates to the port object using patch semantics.
84      * @param original An instance of the Neutron Port object
85      *                  to be updated.
86      * @return A HTTP status code to the update request.
87      */
88     @Override
89     public int canUpdatePort(NeutronPort delta,
90                              NeutronPort original) {
91         int result = HttpURLConnection.HTTP_OK;
92         /**
93          * To basic validation of the request
94          */
95
96         if ((original == null) || (delta == null)) {
97             logger.error("port object not specified");
98             return HttpURLConnection.HTTP_BAD_REQUEST;
99         }
100         return result;
101     }
102
103     /**
104      * Invoked to take action after a port has been updated.
105      *
106      * @param port An instance of modified Neutron Port object.
107      */
108     @Override
109     public void neutronPortUpdated(NeutronPort port) {
110     }
111
112     /**
113      * Invoked when a port deletion is requested
114      * to indicate if the specified port can be deleted.
115      *
116      * @param port     An instance of the Neutron Port object to be deleted.
117      * @return A HTTP status code to the deletion request.
118      */
119     @Override
120     public int canDeletePort(NeutronPort port) {
121         int result = HttpURLConnection.HTTP_OK;
122         return result;
123     }
124
125     /**
126      * Invoked to take action after a port has been deleted.
127      *
128      * @param port  An instance of deleted Neutron Port object.
129      */
130     @Override
131     public void neutronPortDeleted(NeutronPort port) {
132
133         int result = canDeletePort(port);
134         if  (result != HttpURLConnection.HTTP_OK) {
135             logger.error(" deletePort validation failed - result {} ", result);
136             return;
137         }
138
139         String tenantID = convertNeutronIDToKey(port.getTenantID());
140         String networkID = convertNeutronIDToKey(port.getNetworkUUID());
141         String portID = convertNeutronIDToKey(port.getID());
142 /*
143  * Delete the Corresponding OF NodeConnector from the Container
144  *
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);
155         } else {
156             logger.error(" PORT delete successful for tenant-id - {}, " +
157                     " bridge-id - {}, port-id - {}, result - {} ",
158                     tenantID, networkID, portID, status);
159         }
160 */
161         logger.debug(" PORT delete successful for tenant-id - {}, " +
162                      " network-id - {}, port-id - {}", tenantID, networkID, portID);
163
164     }
165 }