Search in sources :

Example 1 with Name

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name in project onos by opennetworkinglab.

the class DcsBasedTapiDataProducer method getNodes.

/**
 * Extract Tapi Nodes from context modelObject and convert them to NodeRefs.
 *
 * @param context
 * @return List of NodeRef
 */
private List<TapiNodeRef> getNodes(DefaultContext context) {
    DefaultAugmentedTapiCommonContext topologyContext = context.augmentation(DefaultAugmentedTapiCommonContext.class);
    Topology topology = topologyContext.topologyContext().topology().get(0);
    if (topology.node() == null) {
        return Collections.emptyList();
    }
    return topology.node().stream().map(node -> {
        TapiNodeRef nodeRef = DcsBasedTapiObjectRefFactory.create(topology, node);
        if (node.name() != null) {
            String deviceId = node.name().stream().filter(kv -> kv.valueName().equals(DEVICE_ID)).findFirst().map(Name::value).get();
            nodeRef.setDeviceId(DeviceId.deviceId(deviceId));
        }
        return nodeRef;
    }).collect(Collectors.toList());
}
Also used : DcsBasedTapiObjectRefFactory(org.onosproject.odtn.utils.tapi.DcsBasedTapiObjectRefFactory) HashMap(java.util.HashMap) DefaultModelObjectData(org.onosproject.yang.model.DefaultModelObjectData) TapiNodeRef(org.onosproject.odtn.utils.tapi.TapiNodeRef) ResourceData(org.onosproject.yang.model.ResourceData) ConnectPoint(org.onosproject.net.ConnectPoint) DataNode(org.onosproject.yang.model.DataNode) Map(java.util.Map) DynamicConfigService(org.onosproject.config.DynamicConfigService) Name(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name) DefaultServiceDirectory.getService(org.onlab.osgi.DefaultServiceDirectory.getService) Logger(org.slf4j.Logger) DefaultResourceData(org.onosproject.yang.model.DefaultResourceData) ModelConverter(org.onosproject.yang.model.ModelConverter) ModelObjectId(org.onosproject.yang.model.ModelObjectId) DefaultContext(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.DefaultContext) Collectors(java.util.stream.Collectors) TapiNepRef(org.onosproject.odtn.utils.tapi.TapiNepRef) ResourceId(org.onosproject.yang.model.ResourceId) DefaultAugmentedTapiTopologyOwnedNodeEdgePoint(org.onosproject.yang.gen.v1.tapiconnectivity.rev20181210.tapiconnectivity.context.topologycontext.topology.node.ownednodeedgepoint.DefaultAugmentedTapiTopologyOwnedNodeEdgePoint) List(java.util.List) CONNECTION_ID(org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID) ModelObjectData(org.onosproject.yang.model.ModelObjectData) Topology(org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.Topology) ODTN_PORT_TYPE(org.onosproject.odtn.utils.tapi.TapiObjectHandler.ODTN_PORT_TYPE) DEVICE_ID(org.onosproject.odtn.utils.tapi.TapiObjectHandler.DEVICE_ID) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Filter(org.onosproject.config.Filter) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) DefaultAugmentedTapiCommonContext(org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.context.DefaultAugmentedTapiCommonContext) ONOS_CP(org.onosproject.odtn.utils.tapi.TapiObjectHandler.ONOS_CP) TapiNodeRef(org.onosproject.odtn.utils.tapi.TapiNodeRef) DefaultAugmentedTapiCommonContext(org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.context.DefaultAugmentedTapiCommonContext) Topology(org.onosproject.yang.gen.v1.tapitopology.rev20181210.tapitopology.topologycontext.Topology) Name(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name)

Example 2 with Name

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name in project onos by opennetworkinglab.

the class OpenConfigComponentHandlerTest method testGetModelObject.

/**
 * UnitTest method for getModelObject.
 */
@Test
public void testGetModelObject() {
    // test Handler
    OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent);
    // expected ModelObject
    DefaultComponent modelObject = new DefaultComponent();
    modelObject.name("name");
    assertEquals("[NG]getModelObject:Return is not an expected ModelObject.\n", modelObject, component.getModelObject());
}
Also used : DefaultComponent(org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.DefaultComponent) Test(org.junit.Test)

Example 3 with Name

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name in project onos by opennetworkinglab.

the class OpenConfigComponentHandlerTest method testAddConfig.

/**
 * UnitTest method for addConfig.
 */
@Test
public void testAddConfig() {
    // test Handler
    OpenConfigComponentHandler component = new OpenConfigComponentHandler("name", parent);
    // call addConfig
    OpenConfigConfigOfComponentHandler config = new OpenConfigConfigOfComponentHandler(component);
    // expected ModelObject
    DefaultComponent modelObject = new DefaultComponent();
    modelObject.name("name");
    DefaultConfig con = new DefaultConfig();
    modelObject.config(con);
    assertEquals("[NG]addConfig:ModelObject(Config added) is not an expected one.\n", modelObject, component.getModelObject());
}
Also used : DefaultComponent(org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.DefaultComponent) DefaultConfig(org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.component.DefaultConfig) Test(org.junit.Test)

Example 4 with Name

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name in project onos by opennetworkinglab.

the class OpenConfigConfigOfAssignmentHandlerTest method testAddLogicalChannel.

/**
 * UnitTest method for addLogicalChannel.
 */
@Test
public void testAddLogicalChannel() {
    // test Handler
    OpenConfigConfigOfAssignmentHandler config = new OpenConfigConfigOfAssignmentHandler(parent);
    // call addLogicalChannel
    config.addLogicalChannel("name");
    // expected ModelObject
    DefaultConfig modelObject = new DefaultConfig();
    modelObject.logicalChannel("name");
    assertEquals("[NG]addLogicalChannel:ModelObject(LogicalChannel added) is not an expected one.\n", modelObject, config.getModelObject());
}
Also used : DefaultConfig(org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20170708.openconfigterminaldevice.terminallogicalchanassignmenttop.logicalchannelassignments.assignment.DefaultConfig) Test(org.junit.Test)

Example 5 with Name

use of org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.Name in project onos by opennetworkinglab.

the class TapiGlobalClassUtil method addNameList.

/**
 * Add key-value to the ModelObject as "name-and-value" list.
 *
 * @param obj ModelObject
 * @param kvs Key-value map
 * @param <T> Type of ModelObject
 */
public static <T extends ModelObject> void addNameList(T obj, Map<String, String> kvs) {
    @SuppressWarnings("unchecked") Class<T> cls = (Class<T>) obj.getClass();
    try {
        Method method = cls.getMethod("addToName", Name.class);
        for (Entry<String, String> kv : kvs.entrySet()) {
            DefaultName prop = new DefaultName();
            prop.valueName(kv.getKey());
            prop.value(kv.getValue());
            method.invoke(obj, prop);
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        log.error("Exception thrown", e);
    }
}
Also used : DefaultName(org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Test (org.junit.Test)6 DefaultComponent (org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.DefaultComponent)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 DefaultConfig (org.onosproject.yang.gen.v1.openconfigplatform.rev20180603.openconfigplatform.platformcomponenttop.components.component.DefaultConfig)2 DefaultName (org.onosproject.yang.gen.v1.tapicommon.rev20181210.tapicommon.globalclass.DefaultName)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 DefaultServiceDirectory.getService (org.onlab.osgi.DefaultServiceDirectory.getService)1 DynamicConfigService (org.onosproject.config.DynamicConfigService)1 Filter (org.onosproject.config.Filter)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 DeviceId (org.onosproject.net.DeviceId)1 CONNECTION_ID (org.onosproject.odtn.behaviour.OdtnDeviceDescriptionDiscovery.CONNECTION_ID)1 DcsBasedTapiObjectRefFactory (org.onosproject.odtn.utils.tapi.DcsBasedTapiObjectRefFactory)1 TapiNepRef (org.onosproject.odtn.utils.tapi.TapiNepRef)1