1
2
3
4
5
6
7
8
9 package org.opendaylight.lispflowmapping.neutron;
10
11 import java.net.HttpURLConnection;
12
13 import org.apache.commons.lang3.exception.ExceptionUtils;
14 import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
15 import org.opendaylight.neutron.spi.INeutronSubnetAware;
16 import org.opendaylight.neutron.spi.NeutronSubnet;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
18
19
20
21
22
23
24
25
26
27
28 public class LispNeutronSubnetHandler extends LispNeutronService implements
29 INeutronSubnetAware {
30 private static final Integer SIX = Integer.valueOf(6);
31
32
33
34 private volatile ILispNeutronService lispNeutronService;
35
36 @Override
37 public int canCreateSubnet(NeutronSubnet subnet) {
38 LOG.info("Neutron canCreateSubnet : Subnet name: " + subnet.getName()
39 + " Subnet Cidr: " + subnet.getCidr());
40 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
41 if (SIX.equals(subnet.getIpVersion())) {
42 return HttpURLConnection.HTTP_PARTIAL;
43 }
44 return HttpURLConnection.HTTP_OK;
45 }
46
47
48
49
50
51
52
53 @Override
54 public void neutronSubnetCreated(NeutronSubnet subnet) {
55
56
57 LOG.info("Neutron Subnet Created request : Subnet name: "
58 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
59 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
60
61
62
63
64 Eid eid = LispAddressUtil.asIpv4PrefixEid(subnet.getCidr());
65
66 try {
67
68 lispNeutronService.getMappingDbService().addKey(LispUtil.buildAddKeyInput(eid, subnet.getNetworkUUID()));
69
70 LOG.debug("Neutron Subnet Added to MapServer : Subnet name: "
71 + subnet.getName() + " EID Prefix: "
72 + subnet.getCidr() + " Key: "
73 + subnet.getNetworkUUID());
74 } catch (Exception e) {
75 LOG.error("Adding new subnet to lisp service mapping service failed. Subnet : "
76 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
77 }
78 LOG.info("Neutron Subnet Created request : Subnet name: "
79 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr());
80
81 }
82
83
84
85
86
87
88
89 @Override
90 public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
91 if (delta == null || original == null) {
92 LOG.error("Neutron canUpdateSubnet rejected: subnet objects were null");
93 return HttpURLConnection.HTTP_BAD_REQUEST;
94 }
95 LOG.info("Neutron canUpdateSubnet : Subnet name: " + original.getName()
96 + " Subnet Cidr: " + original.getCidr());
97 LOG.debug("Lisp Neutron Subnet update: original : "
98 + original.toString() + " delta : " + delta.toString());
99
100
101
102 if (!(original.getCidr().equals(delta.getCidr()))) {
103 LOG.error("Neutron canUpdateSubnet rejected: Subnet name: "
104 + original.getName() + " Subnet Cidr: "
105 + original.getCidr());
106 return HttpURLConnection.HTTP_CONFLICT;
107 }
108 return HttpURLConnection.HTTP_OK;
109 }
110
111 @Override
112 public void neutronSubnetUpdated(NeutronSubnet subnet) {
113
114 }
115
116
117
118
119
120 @Override
121 public int canDeleteSubnet(NeutronSubnet subnet) {
122 LOG.info("Neutron canDeleteSubnet : Subnet name: " + subnet.getName()
123 + " Subnet Cidr: " + subnet.getCidr() + "Key: "
124 + subnet.getNetworkUUID());
125 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
126
127
128 return HttpURLConnection.HTTP_OK;
129 }
130
131
132
133
134
135 @Override
136 public void neutronSubnetDeleted(NeutronSubnet subnet) {
137 LOG.info("Neutron Subnet Deleted Request : Subnet name: "
138 + subnet.getName() + " Subnet Cidr: " + subnet.getCidr()
139 + "Key: " + subnet.getNetworkUUID());
140 LOG.debug("Lisp Neutron Subnet: " + subnet.toString());
141
142
143
144
145 Eid eid = LispAddressUtil.asIpv4PrefixEid(subnet.getCidr());
146
147 try {
148
149 lispNeutronService.getMappingDbService().removeKey(LispUtil.buildRemoveKeyInput(eid));
150
151 LOG.debug("Neutron Subnet Deleted from MapServer : Subnet name: "
152 + subnet.getName() + " Eid Prefix: "
153 + subnet.getCidr() + " Key: "
154 + subnet.getNetworkUUID());
155 } catch (Exception e) {
156 LOG.error("Deleting subnet's EID prefix from mapping service failed + Subnet: "
157 + subnet.toString() + "Error: " + ExceptionUtils.getStackTrace(e));
158 }
159 }
160
161 }