OF Flow programming on br-int (NORMAL) and bidirectional br-tun (based on tenant...
[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         // Create Full Mesh Tunnels
54         /*
55          * Is this required ?
56          * The Tunnel Creation logic is completely owned by the Southbound handler at this point.
57
58         NeutronNetwork network = this.neutronNetworkCache.getNetwork(port.getNetworkUUID());
59         ProviderNetworkManager.getManager().createTunnels(network.getProviderNetworkType(),
60                                                           network.getProviderSegmentationID());
61          */
62         logger.debug(" Port-ADD successful for tenant-id - {}," +
63                 " network-id - {}, port-id - {}, result - {} ",
64                 tenantID, networkID, portID, result);
65     }
66
67     /**
68      * Invoked when a port update is requested
69      * to indicate if the specified port can be changed
70      * using the specified delta.
71      *
72      * @param delta    Updates to the port object using patch semantics.
73      * @param original An instance of the Neutron Port object
74      *                  to be updated.
75      * @return A HTTP status code to the update request.
76      */
77     @Override
78     public int canUpdatePort(NeutronPort delta,
79                              NeutronPort original) {
80         int result = HttpURLConnection.HTTP_OK;
81         /**
82          * To basic validation of the request
83          */
84
85         if ((original == null) || (delta == null)) {
86             logger.error("port object not specified");
87             return HttpURLConnection.HTTP_BAD_REQUEST;
88         }
89         return result;
90     }
91
92     /**
93      * Invoked to take action after a port has been updated.
94      *
95      * @param port An instance of modified Neutron Port object.
96      */
97     @Override
98     public void neutronPortUpdated(NeutronPort port) {
99     }
100
101     /**
102      * Invoked when a port deletion is requested
103      * to indicate if the specified port can be deleted.
104      *
105      * @param port     An instance of the Neutron Port object to be deleted.
106      * @return A HTTP status code to the deletion request.
107      */
108     @Override
109     public int canDeletePort(NeutronPort port) {
110         int result = HttpURLConnection.HTTP_OK;
111         return result;
112     }
113
114     /**
115      * Invoked to take action after a port has been deleted.
116      *
117      * @param port  An instance of deleted Neutron Port object.
118      */
119     @Override
120     public void neutronPortDeleted(NeutronPort port) {
121
122         int result = canDeletePort(port);
123         if  (result != HttpURLConnection.HTTP_OK) {
124             logger.error(" deletePort validation failed - result {} ", result);
125             return;
126         }
127
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);
133
134     }
135 }