org.opendaylight.yangtools.yang.binding.InstanceIdentifier Java Examples

The following examples show how to use org.opendaylight.yangtools.yang.binding.InstanceIdentifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArpSenderTest.java    From atrium-odl with Apache License 2.0 6 votes vote down vote up
@Test
public void testFloodArp() {
	Ipv4Address srcIpv4Address = Ipv4Address.getDefaultInstance("192.168.10.1");
	Ipv4Address dstIpv4Address = Ipv4Address.getDefaultInstance("192.168.20.1");
	MacAddress macAddress = new MacAddress("aa:bb:cc:dd:ee:ff");
	ArpMessageAddress senderAddress = new ArpMessageAddress(macAddress, srcIpv4Address);
	InstanceIdentifier<Node> instanceId = InstanceIdentifier.builder(Nodes.class)
			.child(Node.class, new NodeKey(new NodeId("node_001"))).toInstance();

	Future<RpcResult<Void>> futureTransmitPacketResult = mock(Future.class);

	when(packetProcessingService.transmitPacket(any(TransmitPacketInput.class)))
			.thenReturn(futureTransmitPacketResult);

	arpSender.floodArp(senderAddress, dstIpv4Address, instanceId);

	verify(packetProcessingService, times(1)).transmitPacket(any(TransmitPacketInput.class));
}
 
Example #2
Source File: TransactionHistoryCmd.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Object doExecute() throws Exception {
    Map<InstanceIdentifier<Node>, TransactionHistory> controllerTxLogs
            = hwvtepProvider.getHwvtepConnectionManager().getControllerTxHistory();
    Map<InstanceIdentifier<Node>, TransactionHistory> deviceUpdateLogs
            = hwvtepProvider.getHwvtepConnectionManager().getDeviceUpdateHistory();
    if (nodeid != null) {
        InstanceIdentifier<Node> iid = HwvtepSouthboundMapper.createInstanceIdentifier(new NodeId(nodeid));
        printLogs(controllerTxLogs, deviceUpdateLogs, iid);
    } else {
        Map<InstanceIdentifier<Node>, TransactionHistory> txlogs
                = controllerTxLogs.isEmpty() ? deviceUpdateLogs : controllerTxLogs;
        txlogs.keySet().forEach(iid -> {
            printLogs(controllerTxLogs, deviceUpdateLogs, iid);
        });
        session.getConsole().println("Device tx logs size " + deviceUpdateLogs.keySet().size());
    }
    return null;
}
 
Example #3
Source File: OvsdbBridgeUpdateCommandTest.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testExecute() throws Exception {
    updatedBridgeRows.put(mock(UUID.class), mock(Bridge.class));

    OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class);
    when(ovsdbBridgeUpdateCommand.getOvsdbConnectionInstance()).thenReturn(ovsdbConnectionInstance);
    InstanceIdentifier<Node> connectionIId = mock(InstanceIdentifier.class);
    when(ovsdbConnectionInstance.getInstanceIdentifier()).thenReturn(connectionIId);
    Optional<Node> connection = Optional.of(mock(Node.class));
    PowerMockito.mockStatic(SouthboundUtil.class);
    when(SouthboundUtil.readNode(any(ReadWriteTransaction.class), any(InstanceIdentifier.class)))
            .thenReturn(connection);
    ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
    MemberModifier.suppress(MemberMatcher.method(OvsdbBridgeUpdateCommand.class, "updateBridge",
            ReadWriteTransaction.class, Bridge.class, InstanceIdentifier.class));
    ovsdbBridgeUpdateCommand.execute(transaction);
    verify(ovsdbBridgeUpdateCommand).updateBridge(any(ReadWriteTransaction.class),
            any(Bridge.class), any(InstanceIdentifier.class));
}
 
Example #4
Source File: TransactCommandAggregator.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    boolean readOperationalNodes = false;
    for (DataTreeModification<Node> change : changes) {
        final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
        final DataObjectModification<Node> mod = change.getRootNode();
        final Map<Class<? extends Identifiable>, List<Identifiable>> updatedData = new HashMap<>();
        final Map<Class<? extends Identifiable>, List<Identifiable>> deletedData = new HashMap<>();
        extractDataChanged(key, mod, updatedData, deletedData);
        modifiedData.put(key, Pair.of(updatedData, deletedData));
        operationalState.setModifiedData(modifiedData);
        if (!isMacOnlyUpdate(updatedData, deletedData)) {
            readOperationalNodes = true;
        }
    }
    if (readOperationalNodes) {
        operationalState.readOperationalNodes();
    }
}
 
Example #5
Source File: OvsdbQueueRemovedCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void execute(ReadWriteTransaction transaction) {
    if (removedQueueRows == null || removedQueueRows.isEmpty()) {
        return;
    }

    final InstanceIdentifier<Node> nodeIId = getOvsdbConnectionInstance().getInstanceIdentifier();
    final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, nodeIId);
    if (ovsdbNode.isPresent()) {
        List<InstanceIdentifier<Queues>> result = new ArrayList<>();
        InstanceIdentifier<Node> ovsdbNodeIid =
                SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance().getNodeId());
        for (UUID queueUuid : removedQueueRows.keySet()) {
            QueuesKey queueKey = getQueueKey(ovsdbNode.get(), queueUuid);
            if (queueKey != null) {
                InstanceIdentifier<Queues> iid = ovsdbNodeIid
                    .augmentation(OvsdbNodeAugmentation.class)
                    .child(Queues.class, queueKey);
                result.add(iid);
            }
        }
        deleteQueue(transaction, result);
    }
}
 
Example #6
Source File: OvsdbManagersUpdateCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Update the ManagerEntry values after finding the related {@OpenVSwitch} list.
 *
 * <p>
 * Manager and OpenVSwitch are independent tables in the Open_vSwitch schema
 * but the OVSDB yang model includes the Manager fields in the
 * OvsdbNode data. In some cases the OVSDB will send OpenVSwitch and Manager
 * updates together and in other cases independently. This method here
 * assumes the latter.
 * </p>
 *
 * @param transaction the {@link ReadWriteTransaction}
 * @param newUpdatedManagerRows updated {@link Manager} rows

 */
private void updateManagers(ReadWriteTransaction transaction,
                              Map<Uri, Manager> newUpdatedManagerRows) {

    final InstanceIdentifier<Node> connectionIId = getOvsdbConnectionInstance().getInstanceIdentifier();
    final Optional<Node> ovsdbNode = SouthboundUtil.readNode(transaction, connectionIId);
    if (ovsdbNode.isPresent()) {
        final List<ManagerEntry> managerEntries =
                SouthboundMapper.createManagerEntries(ovsdbNode.get(), newUpdatedManagerRows);

        LOG.debug("Update Ovsdb Node : {} with manager entries : {}",
                ovsdbNode.get(), managerEntries);
        for (ManagerEntry managerEntry : managerEntries) {
            InstanceIdentifier<ManagerEntry> iid = connectionIId
                    .augmentation(OvsdbNodeAugmentation.class)
                    .child(ManagerEntry.class, managerEntry.key());
            transaction.merge(LogicalDatastoreType.OPERATIONAL,
                    iid, managerEntry);
        }
    }
}
 
Example #7
Source File: LinkstateTopologyBuilder.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
private void removeTp(final WriteTransaction trans, final NodeId node, final TpId tp,
        final LinkId link, final boolean isRemote) {
    final NodeHolder nh = this.nodes.get(node);
    if (nh != null) {
        final InstanceIdentifier<Node> nid = getNodeInstanceIdentifier(new NodeKey(nh.getNodeId()));
        trans.delete(LogicalDatastoreType.OPERATIONAL, nid.child(TerminationPoint.class,
                new TerminationPointKey(tp)));
        nh.removeTp(tp, link, isRemote);
        if (!isRemote) {
            nh.createSrHolderIfRequired().removeAdjacencySid(trans, link);
        }
        checkNodeForRemoval(trans, nh);
    } else {
        LOG.warn("Removed non-existent node {}", node.getValue());
    }
}
 
Example #8
Source File: HwvtepDataChangeListener.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private void connect(Collection<DataTreeModification<Node>> changes) {
    for (DataTreeModification<Node> change : changes) {
        final InstanceIdentifier<Node> key = change.getRootPath().getRootIdentifier();
        final DataObjectModification<Node> mod = change.getRootNode();
        Node node = getCreated(mod);
        if (node != null) {
            HwvtepGlobalAugmentation hwvtepGlobal = node.augmentation(HwvtepGlobalAugmentation.class);
            // We can only connect if user configured connection info
            if (hwvtepGlobal != null && hwvtepGlobal.getConnectionInfo() != null) {
                ConnectionInfo connection = hwvtepGlobal.getConnectionInfo();
                InstanceIdentifier<Node> iid = hcm.getInstanceIdentifier(connection);
                if (iid != null) {
                    LOG.warn("Connection to device {} already exists. Plugin does not allow multiple connections "
                                    + "to same device, hence dropping the request {}", connection, hwvtepGlobal);
                } else {
                    try {
                        hcm.connect(key, hwvtepGlobal);
                    } catch (UnknownHostException | ConnectException e) {
                        LOG.warn("Failed to connect to HWVTEP node", e);
                    }
                }
            }
        }
    }
}
 
Example #9
Source File: HwvtepLogicalRouterUpdateCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private void setAclBindings(final LogicalRouter router, final LogicalRoutersBuilder builder) {
    if (isRouterHasAcls(router)) {
        List<AclBindings> bindings = new ArrayList<>();
        for (Entry<String, UUID> entry : router.getAclBindingColumn().getData().entrySet()) {
            AclBindingsBuilder aclBindingBuiler = new AclBindingsBuilder();
            UUID aclUUID = entry.getValue();
            ACL acl = (ACL)getOvsdbConnectionInstance().getDeviceInfo().getDeviceOperData(Acls.class, aclUUID);
            if (acl != null) {
                InstanceIdentifier<Acls> aclIid =
                        HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), acl);
                aclBindingBuiler.setAclRef(new HwvtepAclRef(aclIid));
                aclBindingBuiler.setRouterInterface(new IpPrefix(new Ipv4Prefix(entry.getKey())));
                bindings.add(aclBindingBuiler.build());
            }
            builder.setAclBindings(bindings);
        }
    }
}
 
Example #10
Source File: HwvtepMacEntriesRemoveCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private void removeMcastMacsLocal(ReadWriteTransaction transaction) {
    Collection<McastMacsLocal> deletedLMMRows =
            TyperUtils.extractRowsRemoved(McastMacsLocal.class, getUpdates(), getDbSchema()).values();
    for (McastMacsLocal lmm : deletedLMMRows) {
        if (lmm.getMac() != null && lmm.getLogicalSwitchColumn() != null
                && lmm.getLogicalSwitchColumn().getData() != null) {
            InstanceIdentifier<LocalMcastMacs> lumId = getOvsdbConnectionInstance().getInstanceIdentifier()
                .augmentation(HwvtepGlobalAugmentation.class)
                .child(LocalMcastMacs.class,
                                new LocalMcastMacsKey(getLogicalSwitchRef(lmm.getLogicalSwitchColumn().getData()),
                                                getMacAddress(lmm.getMac())));
            addToDeleteTx(transaction, LocalMcastMacs.class, lumId, lmm.getUuid());
        } else {
            LOG.debug("Failed to delete McastMacLocal entry {}", lmm.getUuid());
        }
    }
}
 
Example #11
Source File: OvsdbConnectionManagerTest.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testDisconnect() throws Exception {
    OvsdbNodeAugmentation ovsdbNode = mock(OvsdbNodeAugmentation.class);
    ConnectionInfo connectionInfo = mock(ConnectionInfo.class);
    when(ovsdbNode.getConnectionInfo()).thenReturn(connectionInfo);
    suppress(MemberMatcher.method(OvsdbConnectionManager.class, "getConnectionInstance", ConnectionInfo.class));
    OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class);
    when(ovsdbConnManager.getConnectionInstance(any(ConnectionInfo.class))).thenReturn(ovsdbConnectionInstance);
    when(ovsdbConnectionInstance.getInstanceIdentifier()).thenReturn(mock(InstanceIdentifier.class));

    suppress(MemberMatcher.method(OvsdbConnectionManager.class, "removeInstanceIdentifier", ConnectionInfo.class));

    // TODO: Write unit tests for entity ownership service related code.
    suppress(MemberMatcher.method(OvsdbConnectionManager.class, "unregisterEntityForOwnership",
            OvsdbConnectionInstance.class));
    ovsdbConnManager.disconnect(ovsdbNode);
    verify(ovsdbConnectionInstance).disconnect();
}
 
Example #12
Source File: BridgeOperationalState.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
public Optional<ControllerEntry> getControllerEntry(InstanceIdentifier<?> iid) {
    if (iid != null) {
        Optional<OvsdbBridgeAugmentation> ovsdbBridgeOptional = getOvsdbBridgeAugmentation(iid);
        if (ovsdbBridgeOptional.isPresent()) {
            Map<ControllerEntryKey, ControllerEntry> entries = ovsdbBridgeOptional.get().getControllerEntry();
            if (entries != null) {
                ControllerEntryKey key = iid.firstKeyOf(ControllerEntry.class);
                if (key != null) {
                    ControllerEntry entry = entries.get(key);
                    if (entry != null) {
                        return Optional.of(entry);
                    }
                }
            }
        }
    }
    return Optional.empty();
}
 
Example #13
Source File: AutoAttachUpdateCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private static OvsdbBridgeAugmentation getBridge(final InstanceIdentifier<OvsdbNodeAugmentation> key,
        final Uri bridgeUri) {
    final InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid = InstanceIdentifier
            .create(NetworkTopology.class)
            .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID))
            .child(Node.class, new NodeKey(new NodeId(bridgeUri)))
            .augmentation(OvsdbBridgeAugmentation.class);

    OvsdbBridgeAugmentation bridge = null;
    try (ReadTransaction transaction = SouthboundProvider.getDb().newReadOnlyTransaction()) {
        final Optional<OvsdbBridgeAugmentation> bridgeOptional =
                transaction.read(LogicalDatastoreType.OPERATIONAL, bridgeIid).get();
        if (bridgeOptional.isPresent()) {
            bridge = bridgeOptional.get();
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("Error reading from datastore", e);
    }
    return bridge;
}
 
Example #14
Source File: BgpDeployerImpl.java    From bgpcep with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public synchronized void onDataTreeChanged(final Collection<DataTreeModification<Bgp>> changes) {
    if (this.closed) {
        LOG.trace("BGP Deployer was already closed, skipping changes.");
        return;
    }

    for (final DataTreeModification<Bgp> dataTreeModification : changes) {
        final InstanceIdentifier<Bgp> rootIdentifier = dataTreeModification.getRootPath().getRootIdentifier();
        final DataObjectModification<Bgp> rootNode = dataTreeModification.getRootNode();
        final List<DataObjectModification<? extends DataObject>> deletedConfig
                = rootNode.getModifiedChildren().stream()
                .filter(mod -> mod.getModificationType() == DataObjectModification.ModificationType.DELETE)
                .collect(Collectors.toList());
        final List<DataObjectModification<? extends DataObject>> changedConfig
                = rootNode.getModifiedChildren().stream()
                .filter(mod -> mod.getModificationType() != DataObjectModification.ModificationType.DELETE)
                .collect(Collectors.toList());
        handleDeletions(deletedConfig, rootIdentifier);
        handleModifications(changedConfig, rootIdentifier);
    }
}
 
Example #15
Source File: HwvtepMacEntriesRemoveCommand.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
private void removeUcastMacsRemote(ReadWriteTransaction transaction) {
    Collection<UcastMacsRemote> deletedUMRRows =
            TyperUtils.extractRowsRemoved(UcastMacsRemote.class, getUpdates(), getDbSchema()).values();
    for (UcastMacsRemote rum : deletedUMRRows) {
        if (rum.getMac() != null && rum.getLogicalSwitchColumn() != null
                && rum.getLogicalSwitchColumn().getData() != null) {
            InstanceIdentifier<RemoteUcastMacs> rumId = getOvsdbConnectionInstance().getInstanceIdentifier()
                .augmentation(HwvtepGlobalAugmentation.class).child(RemoteUcastMacs.class,
                                new RemoteUcastMacsKey(getLogicalSwitchRef(rum.getLogicalSwitchColumn().getData()),
                                                getMacAddress(rum.getMac())));
            addToDeleteTx(transaction, RemoteUcastMacs.class, rumId, rum.getUuid());
        } else {
            LOG.debug("Failed to delete UcastMacRemote entry {}", rum.getUuid());
        }
    }
}
 
Example #16
Source File: DataChangeListenerTestBase.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
Node mergeNode(final LogicalDatastoreType datastoreType, final InstanceIdentifier<Node> id,
        final NodeBuilder nodeBuilder) {
    Node node = nodeBuilder.build();
    WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.mergeParentStructureMerge(datastoreType, id, node);
    transaction.commit();
    return node;
}
 
Example #17
Source File: OvsdbManagersRemovedCommand.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@VisibleForTesting
List<InstanceIdentifier<ManagerEntry>> managerEntriesToRemove(
        InstanceIdentifier<Node> ovsdbNodeIid, OpenVSwitch openVSwitch) {
    Preconditions.checkNotNull(ovsdbNodeIid);
    Preconditions.checkNotNull(openVSwitch);

    List<InstanceIdentifier<ManagerEntry>> result =
            new ArrayList<>();
    OpenVSwitch oldOvsdbNode = oldOpenVSwitchRows.get(openVSwitch.getUuid());

    if (oldOvsdbNode != null && oldOvsdbNode.getManagerOptionsColumn() != null) {
        for (UUID managerUuid: oldOvsdbNode.getManagerOptionsColumn().getData()) {
            if (openVSwitch.getManagerOptionsColumn() == null
                    || !openVSwitch.getManagerOptionsColumn().getData().contains(managerUuid)) {
                Manager manager = removedManagerRows.get(managerUuid);
                if (!checkIfManagerPresentInUpdatedManagersList(manager)) {
                    if (manager != null && manager.getTargetColumn() != null) {
                        InstanceIdentifier<ManagerEntry> iid = ovsdbNodeIid
                                .augmentation(OvsdbNodeAugmentation.class)
                                .child(ManagerEntry.class,
                                        new ManagerEntryKey(
                                                new Uri(manager.getTargetColumn().getData())));
                        result.add(iid);
                    }

                }
            }
        }
    }
    return result;
}
 
Example #18
Source File: DataChangeListenerTestBase.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private void mockConnectionManager() throws IllegalAccessException {
    hwvtepConnectionManager = spy(new HwvtepConnectionManager(dataBroker, transactionInvoker,
        entityOwnershipService, mock(OvsdbConnection.class)));
    doReturn(connectionInstance).when(hwvtepConnectionManager).getConnectionInstance(
        any(HwvtepPhysicalSwitchAttributes.class));
    doReturn(connectionInstance).when(hwvtepConnectionManager).getConnectionInstance(any(Node.class));
    doReturn(connectionInstance).when(hwvtepConnectionManager).getConnectionInstanceFromNodeIid(
        any(InstanceIdentifier.class));
}
 
Example #19
Source File: HwvtepMacEntriesRemoveCommand.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private HwvtepLogicalSwitchRef getLogicalSwitchRef(UUID switchUUID) {
    LogicalSwitch logicalSwitch = getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitch(switchUUID);
    if (logicalSwitch != null) {
        InstanceIdentifier<LogicalSwitches> switchIid =
                HwvtepSouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), logicalSwitch);
        return new HwvtepLogicalSwitchRef(switchIid);
    }
    LOG.debug("Failed to get LogicalSwitch {}", switchUUID);
    LOG.trace("Available LogicalSwitches: {}",
                    getOvsdbConnectionInstance().getDeviceInfo().getLogicalSwitches().values());
    return null;
}
 
Example #20
Source File: HwvtepOperationalState.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
public List<? extends Identifiable> getDeletedData(final InstanceIdentifier<Node> key,
                                                   final Class<? extends Identifiable> cls) {
    List<Identifiable> result = null;
    if (modifiedData.get(key) != null && modifiedData.get(key).getRight() != null) {
        result = modifiedData.get(key).getRight().get(cls);
    }
    if (result == null) {
        result = Collections.EMPTY_LIST;
    }
    return result;
}
 
Example #21
Source File: HwvtepCacheDisplayCmd.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private void printRemoteMcasts(PrintStream console, HwvtepDeviceInfo.DeviceData deviceData) {
    InstanceIdentifier<RemoteMcastMacs> remoteMcastMacsIid = deviceData.getKey();
    String macAddress = remoteMcastMacsIid.firstKeyOf(RemoteMcastMacs.class).getMacEntryKey().getValue();
    String logicalSwitchRef = remoteMcastMacsIid.firstKeyOf(RemoteMcastMacs.class).getLogicalSwitchRef().getValue()
            .firstKeyOf(LogicalSwitches.class).getHwvtepNodeName().getValue();
    StringBuilder macEntryDetails = new StringBuilder(macAddress).append("   LogicalSwitchRef  ")
            .append(logicalSwitchRef);
    console.print(macEntryDetails);
}
 
Example #22
Source File: McastMacsRemoteRemoveCommand.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private void removeMcastMacRemote(final TransactionBuilder transaction,
                                  final InstanceIdentifier<Node> nodeIid, final List<RemoteMcastMacs> macList) {
    for (RemoteMcastMacs mac : macList) {
        InstanceIdentifier<RemoteMcastMacs> macKey = nodeIid.augmentation(HwvtepGlobalAugmentation.class)
                .child(RemoteMcastMacs.class, mac.key());
        onConfigUpdate(transaction, nodeIid, mac, macKey);
    }
}
 
Example #23
Source File: HwvtepOperationalState.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
public Optional<Tunnels> getTunnels(final InstanceIdentifier<?> iid, final TunnelsKey tunnelsKey) {
    Preconditions.checkNotNull(iid);
    Optional<PhysicalSwitchAugmentation> psOptional = getPhysicalSwitchAugmentation(iid);
    if (psOptional.isPresent()) {
        Tunnels tunnel = psOptional.get().nonnullTunnels().get(tunnelsKey);
        if (tunnel != null) {
            return Optional.of(tunnel);
        }
    }
    return Optional.empty();
}
 
Example #24
Source File: BridgeOperationalStateTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetControllerEntry() {
    Optional<ControllerEntry> optController = briOperationState.getControllerEntry(nodeIid);
    verify(briOperationState, times(1)).getOvsdbBridgeAugmentation(any(InstanceIdentifier.class));
    verify(briOperationState, times(1)).getBridgeNode(any(InstanceIdentifier.class));
    assertNotNull(optController);
    assertTrue(optController.equals(Optional.empty()));
}
 
Example #25
Source File: OvsdbNodeRemoveCommandTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testExecute() throws Exception {
    ReadWriteTransaction transaction = mock(ReadWriteTransaction.class);
    FluentFuture<Optional<Node>> ovsdbNodeFuture = mock(FluentFuture.class);
    OvsdbConnectionInstance ovsdbConnectionInstance = mock(OvsdbConnectionInstance.class);
    when(ovsdbNodeRemoveCommand.getOvsdbConnectionInstance()).thenReturn(ovsdbConnectionInstance);
    when(ovsdbConnectionInstance.getInstanceIdentifier()).thenReturn(mock(InstanceIdentifier.class));
    when(transaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class)))
            .thenReturn(ovsdbNodeFuture);

    Node ovsdbNode = mock(Node.class);
    Optional<Node> ovsdbNodeOptional = Optional.of(ovsdbNode);
    when(ovsdbNodeFuture.get()).thenReturn(ovsdbNodeOptional);
    OvsdbNodeAugmentation ovsdbNodeAugmentation = mock(OvsdbNodeAugmentation.class);
    when(ovsdbNode.augmentation(OvsdbNodeAugmentation.class)).thenReturn(ovsdbNodeAugmentation);

    doReturn(true).when(ovsdbNodeRemoveCommand).checkIfOnlyConnectedManager(any(OvsdbNodeAugmentation.class));

    ManagedNodeEntry managedNode = new ManagedNodeEntryBuilder()
            .setBridgeRef(new OvsdbBridgeRef(mock(InstanceIdentifier.class)))
            .build();

    when(ovsdbNodeAugmentation.getManagedNodeEntry()).thenReturn(Map.of(managedNode.key(), managedNode));

    doNothing().when(transaction).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));

    ovsdbNodeRemoveCommand.execute(transaction);
    verify(ovsdbNodeAugmentation).getManagedNodeEntry();
    verify(transaction, times(2)).delete(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
}
 
Example #26
Source File: AppPeerBenchmarkTest.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRpcs() throws Exception {
    final AppPeerBenchmark appPeerBenchmark = new AppPeerBenchmark(getDataBroker(), this.rpcRegistry, PEER_RIB_ID);
    appPeerBenchmark.start();
    final InstanceIdentifier<Ipv4Routes> routesIID = appPeerBenchmark.getIpv4RoutesIID();

    final AddPrefixInput addPrefix = new AddPrefixInputBuilder().setBatchsize(Uint32.ONE).setCount(Uint32.ONE)
            .setNexthop(new Ipv4AddressNoZone(NH)).setPrefix(new Ipv4Prefix(PREFIX)).build();

    final RpcResult<AddPrefixOutput> addRpcResult = appPeerBenchmark.addPrefix(addPrefix).get();
    final Result addResult = addRpcResult.getResult().getResult();
    checkEquals(() -> assertEquals(1, addResult.getCount().intValue()));
    checkEquals(() -> assertEquals(1, addResult.getRate().intValue()));

    readDataConfiguration(getDataBroker(), routesIID, routes -> {
        assertNotNull(routes.getIpv4Route());
        assertEquals(1, routes.getIpv4Route().size());
        return routes;
    });

    final DeletePrefixInput deletePrefix = new DeletePrefixInputBuilder().setBatchsize(Uint32.ONE)
            .setCount(Uint32.ONE).setPrefix(new Ipv4Prefix(PREFIX)).build();
    final RpcResult<DeletePrefixOutput> deleteRpcResult = appPeerBenchmark
            .deletePrefix(deletePrefix).get();
    final Result deleteResult = deleteRpcResult.getResult().getResult();
    checkEquals(() -> assertEquals(1, deleteResult.getCount().intValue()));
    checkEquals(() -> assertEquals(1, deleteResult.getRate().intValue()));

    checkNotPresentConfiguration(getDataBroker(), appPeerBenchmark.getIpv4RoutesIID());

    appPeerBenchmark.close();
}
 
Example #27
Source File: HwvtepSouthboundIT.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void close() {
    final InstanceIdentifier<Node> iid =
                    HwvtepSouthboundUtils.createInstanceIdentifier(connectionInfo, new HwvtepNodeName(psName));
    Assert.assertTrue(mdsalUtils.delete(LogicalDatastoreType.CONFIGURATION, iid));
    try {
        Thread.sleep(OVSDB_UPDATE_TIMEOUT);
    } catch (InterruptedException e) {
        LOG.warn("Sleep interrupted while waiting for bridge deletion (bridge {})", psName, e);
    }
}
 
Example #28
Source File: HwvtepSouthboundIT.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
private void waitForOperationalCreation(InstanceIdentifier<Node> iid) throws InterruptedException {
    synchronized (OPERATIONAL_LISTENER) {
        long start = System.currentTimeMillis();
        LOG.info("Waiting for OPERATIONAL DataChanged creation on {}", iid);
        while (!OPERATIONAL_LISTENER.isCreated(
                iid) && System.currentTimeMillis() - start < OVSDB_ROUNDTRIP_TIMEOUT) {
            OPERATIONAL_LISTENER.wait(OVSDB_UPDATE_TIMEOUT);
        }
        LOG.info("Woke up, waited {} for creation of {}", System.currentTimeMillis() - start, iid);
    }
}
 
Example #29
Source File: BGPOperationalStateUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static Bgp readGlobalFromDataStore(final DataBroker dataBroker, final String ribId) {
    final InstanceIdentifier<Bgp> bgpIID = PROTOCOLS_IID
            .child(Protocol.class, new ProtocolKey(BGP.class, ribId))
            .augmentation(NetworkInstanceProtocol.class).child(Bgp.class);

    final ReadTransaction rot = dataBroker.newReadOnlyTransaction();

    try {
        return rot.read(LogicalDatastoreType.OPERATIONAL, bgpIID).get().orElse(null);
    } catch (final InterruptedException | ExecutionException e) {
        LOG.warn("Failed to read rib {}", ribId, e);
    }
    return null;
}
 
Example #30
Source File: BridgeOperationalStateTest.java    From ovsdb with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    iidNode = InstanceIdentifier.create(NetworkTopology.class)
            .child(Topology.class, new TopologyKey(new TopologyId("foo")))
            .child(Node.class, new NodeKey(nd.getNodeId()));
    protocolEntry = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class).child(Node.class)
            .augmentation(OvsdbBridgeAugmentation.class).child(ProtocolEntry.class);

    briOperationState = mock(BridgeOperationalState.class, Mockito.CALLS_REAL_METHODS);

    getField(BridgeOperationalState.class,"db").set(briOperationState, db);
    doReturn(mockReadTx).when(db).newReadOnlyTransaction();
    OvsdbOperGlobalListener.OPER_NODE_CACHE.put(nodeIid, brNode);
}