VM location aware of Full-mesh Tenant-specific GRE Tunnel support over OF1.0 datapath.
[ovsdb.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / NetworkHandler.java
1 package org.opendaylight.ovsdb.neutron;
2
3 import java.net.HttpURLConnection;
4
5 import org.opendaylight.controller.containermanager.ContainerConfig;
6 import org.opendaylight.controller.networkconfig.neutron.INeutronNetworkAware;
7 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 /**
12  * Handle requests for Neutron Network.
13  */
14 public class NetworkHandler extends BaseHandler
15                             implements INeutronNetworkAware {
16     /**
17      * Logger instance.
18      */
19     static final Logger logger = LoggerFactory.getLogger(NetworkHandler.class);
20
21     /**
22      * Invoked when a network creation is requested
23      * to indicate if the specified network can be created.
24      *
25      * @param network  An instance of proposed new Neutron Network object.
26      * @return A HTTP status code to the creation request.
27      */
28     @Override
29     public int canCreateNetwork(NeutronNetwork network) {
30         if (network.isShared()) {
31             logger.error(" Network shared attribute not supported ");
32             return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
33         }
34
35         return HttpURLConnection.HTTP_CREATED;
36     }
37
38     /**
39      * Invoked to take action after a network has been created.
40      *
41      * @param network  An instance of new Neutron Network object.
42      */
43     @Override
44     public void neutronNetworkCreated(NeutronNetwork network) {
45         int result = HttpURLConnection.HTTP_BAD_REQUEST;
46
47         result = canCreateNetwork(network);
48         if (result != HttpURLConnection.HTTP_CREATED) {
49             logger.debug("Network creation failed {} ", result);
50             return;
51         }
52
53         TenantNetworkManager.getManager().networkCreated(network.getID());
54     }
55
56     /**
57      * Invoked when a network update is requested
58      * to indicate if the specified network can be changed
59      * using the specified delta.
60      *
61      * @param delta     Updates to the network object using patch semantics.
62      * @param original  An instance of the Neutron Network object
63      *                  to be updated.
64      * @return A HTTP status code to the update request.
65      */
66     @Override
67     public int canUpdateNetwork(NeutronNetwork delta,
68                                 NeutronNetwork original) {
69         return HttpURLConnection.HTTP_OK;
70     }
71
72     /**
73      * Invoked to take action after a network has been updated.
74      *
75      * @param network An instance of modified Neutron Network object.
76      */
77     @Override
78     public void neutronNetworkUpdated(NeutronNetwork network) {
79         return;
80     }
81
82     /**
83      * Invoked when a network deletion is requested
84      * to indicate if the specified network can be deleted.
85      *
86      * @param network  An instance of the Neutron Network object to be deleted.
87      * @return A HTTP status code to the deletion request.
88      */
89     @Override
90     public int canDeleteNetwork(NeutronNetwork network) {
91         return HttpURLConnection.HTTP_OK;
92     }
93
94     /**
95      * Invoked to take action after a network has been deleted.
96      *
97      * @param network  An instance of deleted Neutron Network object.
98      */
99     @Override
100     public void neutronNetworkDeleted(NeutronNetwork network) {
101
102         int result = canDeleteNetwork(network);
103         if  (result != HttpURLConnection.HTTP_OK) {
104             logger.error(" deleteNetwork validation failed for result - {} ",
105                     result);
106             return;
107         }
108         String networkID = convertNeutronIDToKey(network.getID());
109
110         ContainerConfig config = new ContainerConfig();
111         config.setContainer(networkID);
112         containerManager.removeContainer(config);
113     }
114 }