Separate privileged methods to MappingAdminService

Change-Id: I8cb32fe027ed70e6d37a8069403224ef4a1fd224
This commit is contained in:
Jian Li 2017-03-12 22:42:56 +09:00
parent f4ba44f7fc
commit cdd1bfd9b9
5 changed files with 50 additions and 62 deletions

View File

@ -15,8 +15,46 @@
*/
package org.onosproject.mapping;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
/**
* Service for administering the mapping management.
*/
public interface MappingAdminService extends MappingService {
/**
* Stores a mapping entry.
*
* @param type mapping store type
* @param entry mapping entry to be stored
*/
void storeMappingEntry(MappingStore.Type type, MappingEntry entry);
/**
* Removes the specified mapping entries from their respective devices and
* mapping store.
*
* @param type mapping store type
* @param entries one or more mapping entries
*/
void removeMappingEntries(MappingStore.Type type, MappingEntry... entries);
/**
* Removes all mapping entries submitted by a particular application.
*
* @param type mapping store type
* @param appId identifier of application whose mapping entries will be removed
*/
void removeMappingEntriesByAppId(MappingStore.Type type, ApplicationId appId);
/**
* Purges all mappings on the specified device and mapping store.
* Note that the mappings will only be removed from storage, the mappings
* are still remaining in the device.
*
* @param type mapping store type
* @param deviceId device identifier
*/
void purgeMappings(MappingStore.Type type, DeviceId deviceId);
}

View File

@ -34,14 +34,6 @@ public interface MappingService
*/
int getMappingCount(Type type);
/**
* Stores a mapping entry.
*
* @param type mapping store type
* @param entry mapping entry to be stored
*/
void storeMappingEntry(Type type, MappingEntry entry);
/**
* Obtains the collection of mapping entries applied on the specific device.
* The will include mapping which may not yet have been applied to device.
@ -60,31 +52,4 @@ public interface MappingService
* @return collection of mapping entries
*/
Iterable<MappingEntry> getMappingEntriesByAddId(Type type, ApplicationId appId);
/**
* Removes the specified mapping entries from their respective devices and
* mapping store.
*
* @param type mapping store type
* @param entries one or more mapping entries
*/
void removeMappingEntries(Type type, MappingEntry... entries);
/**
* Removes all mapping entries submitted by a particular application.
*
* @param type mapping store type
* @param appId identifier of application whose mapping entries will be removed
*/
void removeMappingEntriesByAppId(Type type, ApplicationId appId);
/**
* Purges all mappings on the specified device and mapping store.
* Note that the mappings will only be removed from storage, the mappings
* are still remaining in the device.
*
* @param type mapping store type
* @param deviceId device identifier
*/
void purgeMappings(Type type, DeviceId deviceId);
}

View File

@ -38,10 +38,6 @@ public class MappingServiceAdapter implements MappingService {
return 0;
}
@Override
public void storeMappingEntry(Type type, MappingEntry entry) {
}
@Override
public Iterable<MappingEntry> getMappingEntries(Type type, DeviceId deviceId) {
@ -52,19 +48,4 @@ public class MappingServiceAdapter implements MappingService {
public Iterable<MappingEntry> getMappingEntriesByAddId(Type type, ApplicationId appId) {
return null;
}
@Override
public void removeMappingEntries(Type type, MappingEntry... mappingEntries) {
}
@Override
public void removeMappingEntriesByAppId(Type type, ApplicationId appId) {
}
@Override
public void purgeMappings(Type type, DeviceId deviceId) {
}
}

View File

@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.ApplicationId;
import org.onosproject.mapping.MappingAdminService;
import org.onosproject.mapping.MappingEntry;
import org.onosproject.mapping.MappingEvent;
import org.onosproject.mapping.MappingListener;
@ -53,7 +54,7 @@ import static org.slf4j.LoggerFactory.getLogger;
public class MappingManager
extends AbstractListenerProviderRegistry<MappingEvent, MappingListener,
MappingProvider, MappingProviderService>
implements MappingService, MappingProviderRegistry {
implements MappingService, MappingAdminService, MappingProviderRegistry {
private final Logger log = getLogger(getClass());

View File

@ -27,6 +27,7 @@ import org.onosproject.core.DefaultApplicationId;
import org.onosproject.mapping.DefaultMapping;
import org.onosproject.mapping.DefaultMappingEntry;
import org.onosproject.mapping.Mapping;
import org.onosproject.mapping.MappingAdminService;
import org.onosproject.mapping.MappingEntry;
import org.onosproject.mapping.MappingEvent;
import org.onosproject.mapping.MappingKey;
@ -82,6 +83,7 @@ public class MappingManagerTest {
private MappingManager manager;
private MappingService service;
private MappingAdminService adminService;
private MappingProviderRegistry registry;
private MappingProviderService providerService;
private TestProvider provider;
@ -96,6 +98,7 @@ public class MappingManagerTest {
manager.deviceService = new TestDeviceService();
service = manager;
adminService = manager;
registry = manager;
manager.activate();
@ -160,7 +163,7 @@ public class MappingManagerTest {
private Mapping addMapping(Type type, int tval) {
Mapping mapping = mapping(tval, tval);
MappingEntry entry = new DefaultMappingEntry(mapping);
service.storeMappingEntry(type, entry);
adminService.storeMappingEntry(type, entry);
assertNotNull("mapping should be found",
service.getMappingEntries(type, LISP_DID));
@ -209,9 +212,9 @@ public class MappingManagerTest {
assertTrue("store should be empty", Sets.newHashSet(
service.getMappingEntries(MAP_DATABASE, LISP_DID)).isEmpty());
service.storeMappingEntry(MAP_DATABASE, me1);
service.storeMappingEntry(MAP_DATABASE, me2);
service.storeMappingEntry(MAP_DATABASE, me3);
adminService.storeMappingEntry(MAP_DATABASE, me1);
adminService.storeMappingEntry(MAP_DATABASE, me2);
adminService.storeMappingEntry(MAP_DATABASE, me3);
assertEquals("3 mappings should exist", 3, mappingCount(MAP_DATABASE));
}
@ -229,7 +232,7 @@ public class MappingManagerTest {
MappingEntry me1 = new DefaultMappingEntry(m1);
MappingEntry me2 = new DefaultMappingEntry(m2);
service.removeMappingEntries(MAP_DATABASE, me1, me2);
adminService.removeMappingEntries(MAP_DATABASE, me1, me2);
assertEquals("1 mappings should exist", 1, mappingCount(MAP_DATABASE));
}
@ -244,7 +247,7 @@ public class MappingManagerTest {
addMapping(MAP_DATABASE, 3);
assertEquals("3 mappings should exist", 3, mappingCount(MAP_DATABASE));
service.purgeMappings(MAP_DATABASE, LISP_DID);
adminService.purgeMappings(MAP_DATABASE, LISP_DID);
assertEquals("0 mappings should exist", 0, mappingCount(MAP_DATABASE));
}
@ -269,7 +272,7 @@ public class MappingManagerTest {
addMapping(MAP_DATABASE, 1);
addMapping(MAP_DATABASE, 2);
service.removeMappingEntriesByAppId(MAP_DATABASE, appId);
adminService.removeMappingEntriesByAppId(MAP_DATABASE, appId);
assertTrue("should not have any mappings",
Lists.newLinkedList(