use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey in project lispflowmapping by opendaylight.
the class LispSouthboundPlugin method restoreDaoFromDatastore.
/**
* Restore all keys from MDSAL datastore.
*/
public void restoreDaoFromDatastore() {
final List<AuthenticationKey> authKeys = dsbe.getAllAuthenticationKeys();
LOG.info("Restoring {} keys from datastore into southbound DAO", authKeys.size());
for (AuthenticationKey authKey : authKeys) {
final Eid key = authKey.getEid();
final MappingAuthkey mappingAuthkey = authKey.getMappingAuthkey();
LOG.debug("Adding authentication key '{}' with key-ID {} for {}", mappingAuthkey.getKeyString(), mappingAuthkey.getKeyType(), LispAddressStringifier.getString(key));
akdb.addAuthenticationKey(key, mappingAuthkey);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey in project lispflowmapping by opendaylight.
the class AuthenticationKeyDataListener method onDataTreeChanged.
@Override
public synchronized void onDataTreeChanged(Collection<DataTreeModification<AuthenticationKey>> changes) {
for (DataTreeModification<AuthenticationKey> change : changes) {
final DataObjectModification<AuthenticationKey> mod = change.getRootNode();
if (ModificationType.DELETE == mod.getModificationType()) {
final AuthenticationKey authKey = mod.getDataBefore();
LOG.trace("Received deleted data");
LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
LOG.trace("Value: {}", authKey);
final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
akdb.removeAuthenticationKey(convertedAuthKey.getEid());
updatedEntries.put(convertedAuthKey.getEid(), System.currentTimeMillis());
} else if (ModificationType.WRITE == mod.getModificationType() || ModificationType.SUBTREE_MODIFIED == mod.getModificationType()) {
if (ModificationType.WRITE == mod.getModificationType()) {
LOG.trace("Received created data");
} else {
LOG.trace("Received updated data");
}
// Process newly created or updated authentication keys
final AuthenticationKey authKey = mod.getDataAfter();
LOG.trace("Key: {}", change.getRootPath().getRootIdentifier());
LOG.trace("Value: {}", authKey);
final AuthenticationKey convertedAuthKey = convertToBinaryIfNecessary(authKey);
akdb.addAuthenticationKey(convertedAuthKey.getEid(), convertedAuthKey.getMappingAuthkey());
updatedEntries.put(convertedAuthKey.getEid(), System.currentTimeMillis());
} else {
LOG.warn("Ignoring unhandled modification type {}", mod.getModificationType());
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey in project lispflowmapping by opendaylight.
the class MappingSystemTest method restoreDaoFromDatastoreTest.
/**
* Tests {@link MappingSystem#restoreDaoFromDatastore} method.
*/
@Test
public void restoreDaoFromDatastoreTest() {
final Mapping mapping_1 = new MappingBuilder().setOrigin(MappingOrigin.Northbound).setMappingRecord(getDefaultMappingRecordBuilder().setEid(EID_IPV4_1).build()).build();
final Mapping mapping_2 = new MappingBuilder().setOrigin(MappingOrigin.Northbound).setMappingRecord(getDefaultMappingRecordBuilder().setEid(EID_IPV4_2).build()).build();
final MappingAuthkey mappingAuthkey_1 = MAPPING_AUTHKEY_BUILDER.build();
final AuthenticationKey authenticationKey_1 = new AuthenticationKeyBuilder().setMappingAuthkey(mappingAuthkey_1).setEid(EID_IPV4_1).build();
final MappingAuthkey mappingAuthkey_2 = MAPPING_AUTHKEY_BUILDER.setKeyString("pass-2").build();
final AuthenticationKey authenticationKey_2 = new AuthenticationKeyBuilder().setMappingAuthkey(mappingAuthkey_2).setEid(EID_IPV4_2).build();
final List<Mapping> mappings = Lists.newArrayList(mapping_1, mapping_2);
final List<AuthenticationKey> authenticationKeys = Lists.newArrayList(authenticationKey_1, authenticationKey_2);
Mockito.when(dsbeMock.getLastUpdateTimestamp()).thenReturn(System.currentTimeMillis());
Mockito.when(dsbeMock.getAllMappings(LogicalDatastoreType.CONFIGURATION)).thenReturn(mappings);
Mockito.when(dsbeMock.getAllAuthenticationKeys()).thenReturn(authenticationKeys);
Mockito.when(tableMapMock.get(MappingOrigin.Northbound)).thenReturn(pmcMock);
mappingSystem.initialize();
ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
Mockito.verify(pmcMock).addMapping(Mockito.eq(EID_IPV4_1), captor.capture());
assertEquals(captor.getValue().getRecord(), mapping_1.getMappingRecord());
Mockito.verify(pmcMock).addMapping(Mockito.eq(EID_IPV4_2), captor.capture());
assertEquals(captor.getValue().getRecord(), mapping_2.getMappingRecord());
Mockito.verify(akdbMock).addAuthenticationKey(EID_IPV4_1, mappingAuthkey_1);
Mockito.verify(akdbMock).addAuthenticationKey(EID_IPV4_2, mappingAuthkey_2);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey in project lispflowmapping by opendaylight.
the class AuthenticationKeyDataListenerTest method init.
@Before
@SuppressWarnings("unchecked")
public void init() {
DataBroker dataBrokerMock = Mockito.mock(DataBroker.class);
iMappingSystemMock = Mockito.mock(IMappingSystem.class);
authenticationKeyDataListener = new AuthenticationKeyDataListener(dataBrokerMock, iMappingSystemMock);
final InstanceIdentifier<AuthenticationKey> instanceIdentifierMock = Mockito.mock(InstanceIdentifier.class);
final DataTreeIdentifier<AuthenticationKey> dataTreeIdentifier = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, instanceIdentifierMock);
change_del = Mockito.mock(DataTreeModification.class);
change_subtreeModified = Mockito.mock(DataTreeModification.class);
change_write = Mockito.mock(DataTreeModification.class);
mod_del = Mockito.mock(DataObjectModification.class);
mod_subtreeModified = Mockito.mock(DataObjectModification.class);
mod_write = Mockito.mock(DataObjectModification.class);
Mockito.when(change_del.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(change_del.getRootNode()).thenReturn(mod_del);
Mockito.when(change_subtreeModified.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(change_subtreeModified.getRootNode()).thenReturn(mod_subtreeModified);
Mockito.when(change_write.getRootPath()).thenReturn(dataTreeIdentifier);
Mockito.when(change_write.getRootNode()).thenReturn(mod_write);
Mockito.when(mod_del.getModificationType()).thenReturn(ModificationType.DELETE);
Mockito.when(mod_subtreeModified.getModificationType()).thenReturn(ModificationType.SUBTREE_MODIFIED);
Mockito.when(mod_write.getModificationType()).thenReturn(ModificationType.WRITE);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey in project lispflowmapping by opendaylight.
the class DataStoreBackEnd method getAllAuthenticationKeys.
public List<AuthenticationKey> getAllAuthenticationKeys() {
LOG.debug("MD-SAL: Get all authentication keys from datastore");
List<AuthenticationKey> authKeys = new ArrayList<AuthenticationKey>();
MappingDatabase mdb = readTransaction(DATABASE_ROOT, LogicalDatastoreType.CONFIGURATION);
if (mdb != null && mdb.getVirtualNetworkIdentifier() != null) {
for (VirtualNetworkIdentifier id : mdb.getVirtualNetworkIdentifier()) {
List<AuthenticationKey> keys = id.getAuthenticationKey();
if (keys != null) {
authKeys.addAll(keys);
}
}
}
return authKeys;
}
Aggregations