Search in sources :

Example 46 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project netvirt by opendaylight.

the class L2GatewayListener method update.

@Override
protected void update(InstanceIdentifier<L2gateway> identifier, L2gateway original, L2gateway update) {
    LOG.trace("Updating L2gateway : key: {}, original value={}, update value={}", identifier, original, update);
    List<L2gatewayConnection> connections = l2gwService.getAssociatedL2GwConnections(Sets.newHashSet(update.getUuid()));
    if (connections == null) {
        LOG.warn("There are no connections associated with l2 gateway uuid {} name {}", update.getUuid(), update.getName());
        return;
    }
    if (original.getDevices() == null) {
        connections.forEach((connection) -> l2gwService.addL2GatewayConnection(connection));
        return;
    }
    jobCoordinator.enqueueJob("l2gw.update", () -> {
        ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction();
        DeviceInterfaces updatedDeviceInterfaces = new DeviceInterfaces(update);
        List<ListenableFuture<Void>> fts = new ArrayList<>();
        original.getDevices().stream().filter((originalDevice) -> originalDevice.getInterfaces() != null).forEach((originalDevice) -> {
            String deviceName = originalDevice.getDeviceName();
            L2GatewayDevice l2GwDevice = l2GatewayCache.get(deviceName);
            NodeId physicalSwitchNodeId = HwvtepSouthboundUtils.createManagedNodeId(new NodeId(l2GwDevice.getHwvtepNodeId()), deviceName);
            originalDevice.getInterfaces().stream().filter((intf) -> !updatedDeviceInterfaces.containsInterface(deviceName, intf.getInterfaceName())).forEach((intf) -> {
                connections.forEach((connection) -> {
                    Integer vlanId = connection.getSegmentId();
                    if (intf.getSegmentationIds() != null && !intf.getSegmentationIds().isEmpty()) {
                        for (Integer vlan : intf.getSegmentationIds()) {
                            HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, intf.getInterfaceName(), vlan);
                        }
                    } else {
                        LOG.debug("Deleting vlan binding {} {} {}", physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
                        HwvtepUtils.deleteVlanBinding(transaction, physicalSwitchNodeId, intf.getInterfaceName(), vlanId);
                    }
                });
            });
        });
        fts.add(transaction.submit());
        Futures.addCallback(fts.get(0), new FutureCallback<Void>() {

            @Override
            public void onSuccess(Void success) {
                LOG.debug("Successfully deleted vlan bindings for l2gw update {}", update);
                connections.forEach((l2GwConnection) -> l2gwService.addL2GatewayConnection(l2GwConnection, null, update));
            }

            @Override
            public void onFailure(Throwable throwable) {
                LOG.error("Failed to delete vlan bindings as part of l2gw udpate {}", update);
            }
        }, MoreExecutors.directExecutor());
        return fts;
    }, SystemPropertyReader.getDataStoreJobCoordinatorMaxRetries());
}
Also used : HwvtepSouthboundConstants(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundConstants) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) IL2gwService(org.opendaylight.netvirt.elanmanager.api.IL2gwService) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection) Interfaces(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.devices.Interfaces) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) L2gateways(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.L2gateways) L2gateway(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateways.attributes.l2gateways.L2gateway) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) EntityOwnershipService(org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) HwvtepUtils(org.opendaylight.genius.utils.hwvtep.HwvtepUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AsyncClusteredDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) Map(java.util.Map) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) HwvtepSouthboundUtils(org.opendaylight.genius.utils.hwvtep.HwvtepSouthboundUtils) Devices(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.attributes.Devices) Logger(org.slf4j.Logger) EntityOwnershipUtils(org.opendaylight.genius.utils.clustering.EntityOwnershipUtils) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) Set(java.util.Set) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SystemPropertyReader(org.opendaylight.genius.utils.SystemPropertyReader) Sets(com.google.common.collect.Sets) FutureCallback(com.google.common.util.concurrent.FutureCallback) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) L2gatewayConnections(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.L2gatewayConnections) L2GatewayCache(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayCache) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) ArrayList(java.util.ArrayList) L2GatewayDevice(org.opendaylight.netvirt.neutronvpn.api.l2gw.L2GatewayDevice) NodeId(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) L2gatewayConnection(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l2gateways.rev150712.l2gateway.connections.attributes.l2gatewayconnections.L2gatewayConnection)

Example 47 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project bgpcep by opendaylight.

the class ProtocolsConfigFileProcessor method loadConfiguration.

@Override
public synchronized void loadConfiguration(final NormalizedNode<?, ?> dto) {
    final ContainerNode protocolsContainer = (ContainerNode) dto;
    final MapNode protocolList = (MapNode) protocolsContainer.getChild(protocolYIId.getLastPathArgument()).get();
    final Collection<MapEntryNode> protocolsCollection = protocolList.getValue();
    final WriteTransaction wtx = this.dataBroker.newWriteOnlyTransaction();
    for (final MapEntryNode protocolEntry : protocolsCollection) {
        final Map.Entry<InstanceIdentifier<?>, DataObject> bi = this.bindingSerializer.fromNormalizedNode(this.protocolYIId, protocolEntry);
        if (bi != null) {
            final Protocol protocol = (Protocol) bi.getValue();
            processProtocol(protocol, wtx);
        }
    }
    try {
        wtx.submit().get();
    } catch (final ExecutionException | InterruptedException e) {
        LOG.warn("Failed to create Protocol", e);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Protocol(org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 48 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project bgpcep by opendaylight.

the class NetworkTopologyConfigFileProcessor method loadConfiguration.

@Override
public synchronized void loadConfiguration(final NormalizedNode<?, ?> dto) {
    final ContainerNode networkTopologyContainer = (ContainerNode) dto;
    final MapNode topologyList = (MapNode) networkTopologyContainer.getChild(this.topologyYii.getLastPathArgument()).get();
    final Collection<MapEntryNode> networkTopology = topologyList.getValue();
    if (networkTopology.isEmpty()) {
        return;
    }
    final WriteTransaction wtx = this.dataBroker.newWriteOnlyTransaction();
    for (final MapEntryNode topologyEntry : networkTopology) {
        final Map.Entry<InstanceIdentifier<?>, DataObject> bi = this.bindingSerializer.fromNormalizedNode(this.topologyYii, topologyEntry);
        if (bi != null) {
            processTopology((Topology) bi.getValue(), wtx);
        }
    }
    try {
        wtx.submit().get();
    } catch (final ExecutionException | InterruptedException e) {
        LOG.warn("Failed to create Network Topologies", e);
    }
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 49 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project bgpcep by opendaylight.

the class BaseAbstractRouteEntry method initializeBestPaths.

@Override
@SuppressWarnings("unchecked")
public void initializeBestPaths(final RouteEntryDependenciesContainer entryDep, final RouteEntryInfo entryInfo, final WriteTransaction tx) {
    if (this.bestPath == null) {
        return;
    }
    final TablesKey localTK = entryDep.getLocalTablesKey();
    final Peer toPeer = entryInfo.getToPeer();
    if (!filterRoutes(this.bestPath.getPeerId(), toPeer, localTK)) {
        return;
    }
    final Identifier oldRouteKey = entryInfo.getRouteKey();
    final RIBSupport ribSupport = entryDep.getRibSupport();
    Identifier newRouteKey = ribSupport.createNewRouteKey(this.bestPath.getPathId(), oldRouteKey);
    if (newRouteKey == null) {
        newRouteKey = oldRouteKey;
    }
    final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(this.peerTracker.getPeer(this.bestPath.getPeerId()), toPeer);
    final Optional<Attributes> effAttrib = entryDep.getRoutingPolicies().applyExportPolicies(routeEntry, this.bestPath.getAttributes());
    final Route route = createRoute(ribSupport, newRouteKey, this.bestPath.getPathId(), this.bestPath);
    InstanceIdentifier ribOutIId = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), newRouteKey);
    if (effAttrib.isPresent() && route != null) {
        LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
        tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId, route);
        tx.put(LogicalDatastoreType.OPERATIONAL, ribOutIId.child(Attributes.class), effAttrib.get());
    }
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPRouteEntryExportParametersImpl(org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)

Example 50 with InstanceIdentifier

use of org.opendaylight.yangtools.yang.binding.InstanceIdentifier in project bgpcep by opendaylight.

the class BaseAbstractRouteEntry method removePathFromDataStore.

@SuppressWarnings("unchecked")
private void removePathFromDataStore(final RouteEntryDependenciesContainer entryDep, final Identifier routeKey, final WriteTransaction tx) {
    LOG.trace("Best Path removed {}", this.removedBestPath);
    final KeyedInstanceIdentifier<Tables, TablesKey> locRibTarget = entryDep.getLocRibTableTarget();
    final RIBSupport ribSup = entryDep.getRibSupport();
    Identifier newRouteKey = ribSup.createNewRouteKey(this.removedBestPath.getPathId(), routeKey);
    if (newRouteKey == null) {
        newRouteKey = routeKey;
    }
    final InstanceIdentifier routeTarget = ribSup.createRouteIdentifier(locRibTarget, newRouteKey);
    LOG.debug("Delete route from LocRib {}", routeTarget);
    tx.delete(LogicalDatastoreType.OPERATIONAL, routeTarget);
    fillAdjRibsOut(null, null, newRouteKey, this.removedBestPath.getPeerId(), entryDep, tx);
}
Also used : TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) Tables(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)

Aggregations

InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)142 Logger (org.slf4j.Logger)57 LoggerFactory (org.slf4j.LoggerFactory)57 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)52 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)52 ArrayList (java.util.ArrayList)47 List (java.util.List)47 Collections (java.util.Collections)40 Optional (com.google.common.base.Optional)39 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)37 BigInteger (java.math.BigInteger)36 ManagedNewTransactionRunner (org.opendaylight.genius.infra.ManagedNewTransactionRunner)35 Inject (javax.inject.Inject)34 Singleton (javax.inject.Singleton)34 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)30 ManagedNewTransactionRunnerImpl (org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl)29 JobCoordinator (org.opendaylight.infrautils.jobcoordinator.JobCoordinator)28 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)26 PostConstruct (javax.annotation.PostConstruct)24 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)24