import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.groupbasedpolicy.util.DataStoreHelper;
import org.opendaylight.groupbasedpolicy.util.IidFactory;
import org.opendaylight.groupbasedpolicy.util.NetUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocation;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.AbsoluteLocationBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.InternalLocationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.has.absolute.location.absolute.location.location.type.ExternalLocationCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElements;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.NetworkElementsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.network.elements.rev160407.network.elements.NetworkElement;
}
public synchronized void onEndpointsChange(Collection<DataTreeModification<AddressEndpoint>> changes) {
+ WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
for (DataTreeModification<AddressEndpoint> change : changes) {
switch (change.getRootNode().getModificationType()) {
case DELETE: {
AddressEndpoint endpoint = change.getRootNode().getDataBefore();
- removeLocationForEndpoint(endpoint);
+ removeLocationForEndpoint(endpoint, wtx);
this.endpoints.remove(endpoint);
break;
}
break;
}
endpoint = change.getRootNode().getDataAfter();
- createLocationForEndpoint(endpoint);
+ createLocationForEndpoint(endpoint, wtx);
this.endpoints.add(endpoint);
break;
}
}
}
}
+ DataStoreHelper.submitToDs(wtx);
}
- private void createLocationForEndpoint(AddressEndpoint endpoint) {
+ private void createLocationForEndpoint(AddressEndpoint endpoint, WriteTransaction wtx) {
for (NetworkElement ne : nullToEmpty(networkElements.getNetworkElement())) {
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
&& endpoint.getContextId().equals(en.getL3ContextId())
&& endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils
.samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) {
- WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<AbsoluteLocation> iid = IidFactory
.providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
.child(AbsoluteLocation.class);
wtx.put(LogicalDatastoreType.OPERATIONAL, iid, createRealLocation(ne.getIid(), iface.getIid()),
true);
- wtx.submit();
LOG.debug("New location created for endpoint {}", endpoint);
return;
}
}
}
- private void removeLocationForEndpoint(AddressEndpoint endpoint) {
+ private void removeLocationForEndpoint(AddressEndpoint endpoint, WriteTransaction wtx) {
for (NetworkElement ne : nullToEmpty(networkElements.getNetworkElement())) {
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
&& endpoint.getContextId().equals(en.getL3ContextId())
&& endpoint.getAddressType().isAssignableFrom(IpPrefixType.class) && NetUtils
.samePrefix(new IpPrefix(endpoint.getAddress().toCharArray()), en.getIpPrefix())) {
- WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<AbsoluteLocation> iid = IidFactory
.providerAddressEndpointLocationIid(NE_LOCATION_PROVIDER_NAME, IpPrefixType.class,
endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
.child(AbsoluteLocation.class);
wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
- wtx.submit();
LOG.debug("Location deleted for endpoint {}", endpoint);
return;
}
@Override
public synchronized void onDataTreeChanged(Collection<DataTreeModification<NetworkElements>> changes) {
+ WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
for (DataTreeModification<NetworkElements> change : changes) {
switch (change.getRootNode().getModificationType()) {
case DELETE: {
for (NetworkElement ne : nullToEmpty(nes.getNetworkElement())) {
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processDeletedEN(en);
+ processDeletedEN(en, wtx);
}
}
}
for (NetworkElement ne : nullToEmpty(nes.getNetworkElement())) {
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processDeletedEN(en);
+ processDeletedEN(en, wtx);
}
}
}
for (NetworkElement ne : nullToEmpty(nes.getNetworkElement())) {
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processCreatedEN(en, ne.getIid(), iface.getIid());
+ processCreatedEN(en, ne.getIid(), iface.getIid(), wtx);
}
}
}
List<DataObjectModification<NetworkElement>> modifiedNetworkElements =
getModifiedNetworkElements(change.getRootNode());
for (DataObjectModification<NetworkElement> netElement : modifiedNetworkElements) {
- processNetworkElementChange(netElement);
+ processNetworkElementChange(netElement, wtx);
}
break;
}
}
}
+ DataStoreHelper.submitToDs(wtx);
}
private List<DataObjectModification<NetworkElement>> getModifiedNetworkElements(
return nes;
}
- private void processNetworkElementChange(DataObjectModification<NetworkElement> netElement) {
+ private void processNetworkElementChange(DataObjectModification<NetworkElement> netElement, WriteTransaction wtx) {
switch (netElement.getModificationType()) {
case DELETE: {
NetworkElement ne = netElement.getDataBefore();
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processDeletedEN(en);
+ processDeletedEN(en, wtx);
}
}
networkElements.getNetworkElement().remove(ne);
if (ne != null) {
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processDeletedEN(en);
+ processDeletedEN(en, wtx);
}
}
networkElements.getNetworkElement().remove(ne);
ne = netElement.getDataAfter();
for (Interface iface : nullToEmpty(ne.getInterface())) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processCreatedEN(en, ne.getIid(), iface.getIid());
+ processCreatedEN(en, ne.getIid(), iface.getIid(), wtx);
}
}
networkElements.getNetworkElement().add(ne);
case SUBTREE_MODIFIED: {
List<DataObjectModification<Interface>> modifiedInterfaces = getModifiedInterfaces(netElement);
for (DataObjectModification<Interface> modifiedInterface : modifiedInterfaces) {
- processInterfaceChange(modifiedInterface, netElement.getDataBefore());
+ processInterfaceChange(modifiedInterface, netElement.getDataBefore(), wtx);
}
break;
}
}
private void processInterfaceChange(DataObjectModification<Interface> modifiedInterface,
- NetworkElement nodeBefore) {
+ NetworkElement nodeBefore, WriteTransaction wtx) {
switch (modifiedInterface.getModificationType()) {
case DELETE: {
Interface iface = modifiedInterface.getDataBefore();
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processDeletedEN(en);
+ processDeletedEN(en, wtx);
}
int nodeIndex = getIndexOf(nodeBefore);
networkElements.getNetworkElement().get(nodeIndex).getInterface().remove(iface);
int nodeIndex = getIndexOf(nodeBefore);
if (iface != null) {
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processDeletedEN(en);
+ processDeletedEN(en, wtx);
}
networkElements.getNetworkElement().get(nodeIndex).getInterface().remove(iface);
}
iface = modifiedInterface.getDataAfter();
for (EndpointNetwork en : nullToEmpty(iface.getEndpointNetwork())) {
- processCreatedEN(en, nodeBefore.getIid(), iface.getIid());
+ processCreatedEN(en, nodeBefore.getIid(), iface.getIid(), wtx);
}
networkElements.getNetworkElement().get(nodeIndex).getInterface().add(iface);
LOG.debug("Created new Interface {}", modifiedInterface.getDataAfter());
List<DataObjectModification<EndpointNetwork>> modifiedENs =
getModifiedEndpointNetworks(modifiedInterface);
for (DataObjectModification<EndpointNetwork> modifiedEN : modifiedENs) {
- processEndpointNetworkChange(modifiedEN, nodeBefore, modifiedInterface.getDataBefore());
+ processEndpointNetworkChange(modifiedEN, nodeBefore, modifiedInterface.getDataBefore(), wtx);
}
break;
}
}
private void processEndpointNetworkChange(DataObjectModification<EndpointNetwork> modifiedEN,
- NetworkElement nodeBefore, Interface ifaceBefore) {
+ NetworkElement nodeBefore, Interface ifaceBefore, WriteTransaction wtx) {
switch (modifiedEN.getModificationType()) {
case DELETE: {
- processDeletedEN(modifiedEN.getDataBefore());
+ processDeletedEN(modifiedEN.getDataBefore(), wtx);
int nodeIndex = getIndexOf(nodeBefore);
int ifaceIndex = getIndexOf(ifaceBefore, nodeIndex);
networkElements.getNetworkElement()
break;
}
case WRITE: {
- processCreatedEN(modifiedEN.getDataAfter(), nodeBefore.getIid(), ifaceBefore.getIid());
+ processCreatedEN(modifiedEN.getDataAfter(), nodeBefore.getIid(), ifaceBefore.getIid(), wtx);
int nodeIndex = getIndexOf(nodeBefore);
int ifaceIndex = getIndexOf(ifaceBefore, nodeIndex);
networkElements.getNetworkElement()
}
private void processCreatedEN(EndpointNetwork en, InstanceIdentifier<?> nodeIID,
- InstanceIdentifier<?> connectorIID) {
- WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+ InstanceIdentifier<?> connectorIID, WriteTransaction wtx) {
for (AddressEndpoint endpoint : endpoints) {
if (endpoint.getContextType().isAssignableFrom(L3Context.class)
&& endpoint.getContextId().equals(en.getL3ContextId())
endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
.child(AbsoluteLocation.class);
wtx.put(LogicalDatastoreType.OPERATIONAL, iid, createRealLocation(nodeIID, connectorIID), true);
- wtx.submit();
LOG.debug("New location created for endpoint {}", endpoint);
return;
}
}
}
- private void processDeletedEN(EndpointNetwork en) {
- WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
+ private void processDeletedEN(EndpointNetwork en, WriteTransaction wtx) {
for (AddressEndpoint endpoint : endpoints) {
if (endpoint.getContextType().isAssignableFrom(L3Context.class)
&& endpoint.getContextId().equals(en.getL3ContextId())
endpoint.getAddress(), endpoint.getContextType(), endpoint.getContextId())
.child(AbsoluteLocation.class);
wtx.delete(LogicalDatastoreType.OPERATIONAL, iid);
- wtx.submit();
LOG.debug("Location deleted for endpoint {}", endpoint);
return;
}
private AbsoluteLocation createRealLocation(InstanceIdentifier<?> node, InstanceIdentifier<?> iface) {
return new AbsoluteLocationBuilder()
- .setLocationType(new InternalLocationCaseBuilder().setInternalNode(node).setInternalNodeConnector(iface).build()).build();
+ .setLocationType(new ExternalLocationCaseBuilder().setExternalNodeMountPoint(node)
+ .setExternalNodeConnector(iface.toString()).build()).build();
}
private <T> List<T> nullToEmpty(@Nullable List<T> list) {