private EndpointInfo epInfo;
private EndpointLocationInfo epLocInfo;
private Forwarding forwarding;
+ private boolean changesWaitingToProcess = false;
+ private boolean currentVersionHasConfig = false;
private final EndpointsListener endpointsListener;
private final EndpointLocationsListener endpointLocationsListener;
public synchronized void endpointsUpdated(final Endpoints endpoints) {
epInfo = new EndpointInfo(endpoints);
+ changesWaitingToProcess = true;
processState();
}
public synchronized void endpointLocationsUpdated(final EndpointLocations epLocations) {
epLocInfo = new EndpointLocationInfo(epLocations);
+ changesWaitingToProcess = true;
processState();
}
public synchronized void resolvedPoliciesUpdated(final ResolvedPolicies resolvedPolicies) {
policyInfo = new ResolvedPolicyInfo(resolvedPolicies);
+ changesWaitingToProcess = true;
processState();
}
public synchronized void forwardingUpdated(final Forwarding forwarding) {
this.forwarding = forwarding;
+ changesWaitingToProcess = true;
processState();
}
rendererByNode.put(nodePath, renderers.asList().get(0));
}
if (processingRenderers.isEmpty()) {
- processState();
+ changesWaitingToProcess = true;
} else {
LOG.debug("Waiting for renderers. Version {} needs to be processed by renderers: {}", version,
processingRenderers);
}
}
}
+ processState();
}
private void processState() {
if (rendererByNode.values().isEmpty()) {
return;
}
-
- version++;
+ if (!changesWaitingToProcess) {
+ return;
+ }
Map<RendererName, RendererConfigurationBuilder> rendererConfigBuilderByRendererName = createRendererConfigBuilders();
- List<Renderer> renderers = new ArrayList<>();
Set<RendererName> rendererNames = new HashSet<>(rendererByNode.values());
+ boolean newVersionHasConfig = false;
+ Map<RendererName, Optional<Configuration>> configsByRendererName = new HashMap<>();
for (RendererName rendererName : rendererNames) {
RendererConfigurationBuilder rendererPolicyBuilder = rendererConfigBuilderByRendererName.get(rendererName);
Optional<Configuration> potentialConfig = createConfiguration(rendererPolicyBuilder);
- RendererPolicy rendererPolicy = null;
if (potentialConfig.isPresent()) {
- LOG.debug("Created configuration for renderer with version {}", rendererName.getValue(), version);
- rendererPolicy =
- new RendererPolicyBuilder().setVersion(version).setConfiguration(potentialConfig.get()).build();
+ newVersionHasConfig = true;
+ }
+ configsByRendererName.put(rendererName, potentialConfig);
+ }
+ if (newVersionHasConfig || currentVersionHasConfig) {
+ version++;
+ if (!writeRenderersConfigs(configsByRendererName)) {
+ LOG.warn("Version {} was not dispatched successfully. Previous version is valid until next update.",
+ version);
+ for (RendererName rendererName : rendererConfigBuilderByRendererName.keySet()) {
+ processingRenderers.remove(rendererName);
+ }
+ version--;
+ changesWaitingToProcess = true;
+ return;
+ } else {
+ currentVersionHasConfig = newVersionHasConfig;
+ }
+ }
+ changesWaitingToProcess = false;
+ }
+
+ private boolean writeRenderersConfigs(Map<RendererName, Optional<Configuration>> configsByRendererName) {
+ List<Renderer> renderers = new ArrayList<>();
+ for (RendererName rendererName : configsByRendererName.keySet()) {
+ RendererPolicy rendererPolicy = null;
+ if (configsByRendererName.get(rendererName).isPresent()) {
+ rendererPolicy = new RendererPolicyBuilder().setVersion(version)
+ .setConfiguration(configsByRendererName.get(rendererName).get())
+ .build();
+
} else {
- rendererPolicy =
- new RendererPolicyBuilder().setVersion(version).build();
+ rendererPolicy = new RendererPolicyBuilder().setVersion(version).build();
}
renderers.add(new RendererBuilder().setName(rendererName).setRendererPolicy(rendererPolicy).build());
processingRenderers.add(rendererName);
+ LOG.debug("Created configuration for renderer {} with version {}", rendererName.getValue(), version);
}
WriteTransaction wTx = dataProvider.newWriteOnlyTransaction();
wTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Renderers.class),
new RenderersBuilder().setRenderer(renderers).build());
- if (!DataStoreHelper.submitToDs(wTx)) {
- LOG.warn("Version {} was not dispatched successfully. Previous version is valid till next update.",
- version);
- for (RendererName rendererName : rendererConfigBuilderByRendererName.keySet()) {
- processingRenderers.remove(rendererName);
- }
- version--;
- }
+ return DataStoreHelper.submitToDs(wTx);
}
/**
* Entry is added to the result map only if:<br>
* 1. There is at least one Address EP with absolute location
* 2. There is a renderer responsible for that EP
- *
+ *
* @return
*/
private Map<RendererName, RendererConfigurationBuilder> createRendererConfigBuilders() {
return;
}
for (AddressEndpointKey peerAdrEpKey : peerAdrEps) {
+ if (isSameKeys(rendererEpKey, peerAdrEpKey)) {
+ continue;
+ }
ExternalImplicitGroup eig = policy.getExternalImplicitGroup();
if (eig != null) {
if (!epLocInfo.hasRelativeLocation(peerAdrEpKey)) {
return false;
}
+ private boolean isSameKeys(RendererEndpointKey rendererEpKey, AddressEndpointKey peerAdrEpKey) {
+ if (rendererEpKey.getAddress().equals(peerAdrEpKey.getAddress())
+ && rendererEpKey.getAddressType().equals(peerAdrEpKey.getAddressType())
+ && rendererEpKey.getContextId().equals(peerAdrEpKey.getContextId())
+ && rendererEpKey.getContextType().equals(peerAdrEpKey.getContextType())) {
+ return true;
+ }
+ return false;
+ }
+
private Set<EpgKeyDto> toEpgKeys(List<EndpointGroupId> epgIds, TenantId tenantId) {
return FluentIterable.from(epgIds).transform(new Function<EndpointGroupId, EpgKeyDto>() {
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) {