From: Tony Tkacik Date: Mon, 19 Aug 2013 18:37:51 +0000 (+0200) Subject: Added YANG models for flow configuration, statistics and inventory. X-Git-Tag: releasepom-0.1.0~194^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=3a4033c1c3589c009aa724d7e27c2ac4e312971a Added YANG models for flow configuration, statistics and inventory. Added AbstractBindingAwareConsumer and Provider, updated samples. Change-Id: I72a8707b7e0b4e97d11d9f6f4288f0656d0840e0 Signed-off-by: Tony Tkacik --- diff --git a/opendaylight/sal/yang-prototype/sal/model/model-flow-statistics/pom.xml b/opendaylight/sal/yang-prototype/sal/model/model-flow-statistics/pom.xml new file mode 100644 index 0000000000..98617a8f0d --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/model-flow-statistics/pom.xml @@ -0,0 +1,26 @@ + + + + model-parent + org.opendaylight.controller.model + 1.0-SNAPSHOT + + + 4.0.0 + model-flow-statistics + + + + ${project.groupId} + model-inventory + ${project.version} + + + ${project.groupId} + model-flow + ${project.version} + + + bundle + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/model/model-flow-statistics/src/main/yang/opendaylight-flow-statistics.yang b/opendaylight/sal/yang-prototype/sal/model/model-flow-statistics/src/main/yang/opendaylight-flow-statistics.yang new file mode 100644 index 0000000000..36d8bf2a99 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/model-flow-statistics/src/main/yang/opendaylight-flow-statistics.yang @@ -0,0 +1,82 @@ +module opendaylight-flow-statistics { + namespace "urn:opendaylight:flow:statistics"; + prefix flowstat; + + import yang-ext {prefix ext;} + import ietf-inet-types {prefix inet;} + import ietf-yang-types {prefix yang;} + import opendaylight-flow {prefix flow;} + import opendaylight-inventory {prefix inv;} + + revision "2013-08-19" { + description "Initial revision of flow service"; + } + + augment "/flow:flows/flow:flow" { + ext:augment-identifier "flow-statistics"; + + leaf packet-count { + type uint64; + } + + leaf byte-count { + type uint64; + } + + container duration { + leaf second { + type uint64; + } + leaf nanosecond { + type uint64; + } + } + } + + augment "/inv:nodes/inv:node/inv:node-connector" { + ext:augment-identifier "node-connector-statistics"; + + container packets { + leaf received { + type uint64; + } + leaf transmitted { + type uint64; + } + } + container bytes { + leaf received { + type uint64; + } + leaf transmitted { + type uint64; + } + } + leaf receive-drops { + type uint64; + } + leaf transmit-drops { + type uint64; + } + leaf receive-errors { + type uint64; + } + leaf transmit-errors { + type uint64; + } + leaf receive-frame-error { + type uint64; + } + leaf receive-over-run-error { + type uint64; + } + leaf receive-crc-error { + type uint64; + } + leaf collision-count { + type uint64; + } + + } + +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/model/model-flow/pom.xml b/opendaylight/sal/yang-prototype/sal/model/model-flow/pom.xml new file mode 100644 index 0000000000..7c878fa302 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/model-flow/pom.xml @@ -0,0 +1,21 @@ + + + + model-parent + org.opendaylight.controller.model + 1.0-SNAPSHOT + + + 4.0.0 + model-flow + + + + ${project.groupId} + model-inventory + ${project.version} + + + bundle + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/model/model-flow/src/main/yang/opendaylight-flow.yang b/opendaylight/sal/yang-prototype/sal/model/model-flow/src/main/yang/opendaylight-flow.yang new file mode 100644 index 0000000000..1f94ef98ee --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/model-flow/src/main/yang/opendaylight-flow.yang @@ -0,0 +1,266 @@ +module opendaylight-flow { + namespace "urn:opendaylight:flow:service"; + prefix flow; + + import yang-ext {prefix ext;} + import ietf-inet-types {prefix inet;} + import ietf-yang-types {prefix yang;} + import opendaylight-inventory {prefix inv;} + + revision "2013-08-19" { + description "Initial revision of flow service"; + } + + /** Base structure **/ + container flows { + list flow { + leaf node { + type inv:node-id; + } + container match { + // Match is empty + leaf input-node-connector { + type inv:node-connector-id; // + } + } + list action { + key id; + leaf id { + type string; + } + choice action { + + } + } + } + } + + /** Matches **/ + augment "/flows/flow/match" { + ext:augment-identifier "ethernet-match"; + container ethernet-source { + description "Ethernet source address."; + leaf address { + type yang:mac-address; + } + leaf mask { + type binary; + } + } + container ethernet-destination { + description "Ethernet destination address."; + leaf address { + type yang:mac-address; + } + } + container ethernet-type { + description "Ethernet frame type."; + leaf type { + type uint16; // Needs to define that as general model + } + leaf mask { + type binary; + } + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "vlan-match"; + + container vlan-id { + description "VLAN id."; + leaf vlan-id { + type uint16; // TODO: Define proper vlan id type. + } + leaf mask { + type binary; + } + } + leaf vlan-pcp { + description "VLAN priority."; + type uint8; // TODO: Define PCP type + } + + + } + + augment "/flows/flow/match" { + ext:augment-identifier "ip-match"; + + leaf ip-protocol { + description "IP protocol."; + type uint8; // TODO define IP protocol number + } + + leaf ip-dscp { + description "IP DSCP (6 bits in ToS field)."; + type inet:dscp; // TODO: Define DSCP type + } + leaf ip-ecn { + description "IP ECN (2 bits in ToS field)."; + type uint8; // TODO define ECN + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "ipv4-match"; + leaf ipv4-source { + description "IPv4 source address."; + type inet:ipv4-prefix; + } + leaf ipv4-destination { + description "IPv4 destination address."; + type inet:ipv4-prefix; + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "ipv6-match"; + leaf ipv6-source { + description "IPv6 source address."; + type inet:ipv6-prefix; + } + leaf ipv6-destination { + description "IPv6 destination address."; + type inet:ipv6-prefix; + } + } + + + augment "/flows/flow/match" { + ext:augment-identifier "udp-match"; + + leaf udp-source-port { + description "UDP source port."; + type inet:port-number; + } + leaf udp-destination-port { + description "UDP destination port."; + type inet:port-number; + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "tcp-match"; + leaf tcp-source-port { + description "TCP source port."; + type inet:port-number; + } + leaf tcp-destination-port { + description "TCP destination port."; + type inet:port-number; + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "sctp-match"; + leaf sctp-source-port { + description "SCTP source port."; + type inet:port-number; + } + leaf sctp-destination-dst { + description "SCTP destination port."; + type inet:port-number; + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "icmpv4-match"; + leaf icmpv4-type { + description "ICMP type."; + type uint8; // Define ICMP Type + } + description "ICMP code."; + leaf icmpv4-code { + type uint8; // Define ICMP Code + } + } + + augment "/flows/flow/match" { + ext:augment-identifier "arp-match"; + + leaf arp-source-transport-address { + description "ARP source IPv4 address."; + type inet:ipv4-prefix; + } + + leaf arp-target-transport-address { + description "ARP target IPv4 address."; + type inet:ipv4-prefix; + } + container arp-source-hardware-address { + description "ARP source hardware address."; + leaf address { + type yang:mac-address; + } + leaf mask { + type binary; + } + } + container arp-target-hardware-address { + description "ARP target hardware address."; + leaf address { + type yang:mac-address; + } + leaf mask { + type binary; + } + } + } + + /** Actions **/ + augment "/flows/flow/action/action" { + case output-action { + leaf output-node-connector { + type string; + } + } + + case controller-action { + leaf max-length { + type uint16 { + range "0..65294"; + } + } + } + + case set-queue-action { + leaf queue { + type string; // TODO: define queues + } + } + + case pop-mpls-action { + container pop-mpls { + leaf ethernet-type { + type uint16; // TODO: define ethertype type + } + } + } + + case set-mpls-ttl-action { + leaf mpls-ttl { + type uint8; + } + } + + case set-nw-ttl-action { + leaf nw-ttl { + type uint8; + } + } + + case push-pbb-action { + + } + + case push-mpls-action { + + } + + case push-vlan-action { + + } + } + +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/model/model-inventory/pom.xml b/opendaylight/sal/yang-prototype/sal/model/model-inventory/pom.xml new file mode 100644 index 0000000000..0de70e3b55 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/model-inventory/pom.xml @@ -0,0 +1,13 @@ + + + + model-parent + org.opendaylight.controller.model + 1.0-SNAPSHOT + + + 4.0.0 + model-inventory + bundle + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/model/model-inventory/src/main/yang/opendaylight-inventory.yang b/opendaylight/sal/yang-prototype/sal/model/model-inventory/src/main/yang/opendaylight-inventory.yang new file mode 100644 index 0000000000..9f2590b181 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/model-inventory/src/main/yang/opendaylight-inventory.yang @@ -0,0 +1,34 @@ +module opendaylight-inventory { + namespace "urn:opendaylight:inventory"; + prefix flow; + + import yang-ext {prefix ext;} + import ietf-inet-types {prefix inet;} + import ietf-yang-types {prefix yang;} + + + revision "2013-08-19" { + description "Initial revision of Inventory model"; + } + + typedef node-id { + type inet:uri; + } + + typedef node-connector-id { + type inet:uri; + } + + /** Base structure **/ + container nodes { + list node { + key id; + leaf id { + type node-id; + } + list node-connector { + type node-connector-id; + } + } + } +} \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/model/pom.xml b/opendaylight/sal/yang-prototype/sal/model/pom.xml new file mode 100644 index 0000000000..4ce4dcb3a7 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/pom.xml @@ -0,0 +1,163 @@ + + + + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + + + 4.0.0 + org.opendaylight.controller.model + model-parent + 1.0-SNAPSHOT + pom + + + 0.5.7-SNAPSHOT + UTF-8 + 2.4.0 + + + + model-inventory + model-flow + model-flow-statistics + + + + + + + org.apache.felix + maven-bundle-plugin + ${maven.bundle.version} + true + + + ${project.groupId}.${project.artifactId} + + + + + org.opendaylight.yangtools + yang-maven-plugin + ${yang.version} + + + + generate-sources + + + src/main/yang + + + + org.opendaylight.yangtools.maven.sal.api.gen.plugin.CodeGeneratorImpl + + + target/generated-sources/sal + + + + true + + + + + + org.opendaylight.yangtools + maven-sal-api-gen-plugin + 0.5.7-SNAPSHOT + jar + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.7 + + + generate-sources + + add-source + + + + target/generated-sources/sal + + + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.opendaylight.yangtools + + + yang-maven-plugin + + + [0.5,) + + + + generate-sources + + + + + + + + + + + + + + + + + + org.opendaylight.yangtools + yang-binding + ${yang.version} + + + org.opendaylight.yangtools + yang-common + ${yang.version} + + + org.opendaylight.yangtools.model + ietf-inet-types + 2010.09.24-SNAPSHOT + + + org.opendaylight.yangtools.model + ietf-yang-types + 2010.09.24-SNAPSHOT + + + org.opendaylight.yangtools + yang-ext + 2013.09.07-SNAPSHOT + + + + diff --git a/opendaylight/sal/yang-prototype/sal/model/src/main/yang/.gitignore b/opendaylight/sal/yang-prototype/sal/model/src/main/yang/.gitignore new file mode 100644 index 0000000000..d40e041635 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/model/src/main/yang/.gitignore @@ -0,0 +1 @@ +*.yang \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/pom.xml b/opendaylight/sal/yang-prototype/sal/pom.xml index a3d95bdf30..3b38c1eee7 100644 --- a/opendaylight/sal/yang-prototype/sal/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/pom.xml @@ -13,6 +13,7 @@ sal-binding-api sal-binding-broker-impl samples + model diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBindingAwareConsumer.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBindingAwareConsumer.java new file mode 100644 index 0000000000..b90bd23886 --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBindingAwareConsumer.java @@ -0,0 +1,23 @@ +package org.opendaylight.controller.sal.binding.api; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public abstract class AbstractBindingAwareConsumer implements BindingAwareConsumer,BundleActivator { + + @Override + public final void start(BundleContext context) throws Exception { + ServiceReference brokerRef = context.getServiceReference(BindingAwareBroker.class); + BindingAwareBroker broker = context.getService(brokerRef); + broker.registerConsumer(this, context); + //context.ungetService(brokerRef); + } + + @Override + public final void stop(BundleContext context) throws Exception { + // TODO Auto-generated method stub + + } + +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBindingAwareProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBindingAwareProvider.java new file mode 100644 index 0000000000..dbdedc359e --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/AbstractBindingAwareProvider.java @@ -0,0 +1,21 @@ +package org.opendaylight.controller.sal.binding.api; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public abstract class AbstractBindingAwareProvider implements BindingAwareProvider, BundleActivator { + + @Override + public final void start(BundleContext context) throws Exception { + ServiceReference brokerRef = context.getServiceReference(BindingAwareBroker.class); + BindingAwareBroker broker = context.getService(brokerRef); + broker.registerProvider(this, context); + } + + @Override + public final void stop(BundleContext context) throws Exception { + + + } +} diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java index fa104882a3..87008cd14b 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/BindingAwareBroker.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.sal.binding.api; import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; -import org.opendaylight.controller.sal.binding.api.data.DataConsumerService; +import org.opendaylight.controller.sal.binding.api.data.DataProviderService; import org.opendaylight.yangtools.yang.binding.RpcService; import org.osgi.framework.BundleContext; @@ -35,7 +35,7 @@ import org.osgi.framework.BundleContext; * {@link NotificationProviderService} *
  • Functionality and Data model *
  • Data Store access and modification - see {@link DataBrokerService} and - * {@link DataConsumerService} + * {@link DataProviderService} * * * The services are exposed via session. diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java index 250aaf35c0..dd055aa382 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataBrokerService.java @@ -19,7 +19,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult; * system. * * - * @see DataConsumerService + * @see DataProviderService */ public interface DataBrokerService extends BindingAwareService { diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java index 7b965d16f2..ea5a16e27b 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataCommitHandler.java @@ -191,7 +191,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult; * {@link Provider#getProviderFunctionality()} *
  • passing an instance of implementation and {@link DataStoreIdentifier} of * rpc as arguments to the - * {@link DataConsumerService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)} + * {@link DataProviderService#addCommitHandler(DataStoreIdentifier, DataCommitHandler)} * * * diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataProviderService.java similarity index 96% rename from opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java rename to opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataProviderService.java index e57ce4d9ba..857b07b5c7 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataConsumerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/DataProviderService.java @@ -9,7 +9,7 @@ package org.opendaylight.controller.sal.binding.api.data; import org.opendaylight.controller.sal.common.DataStoreIdentifier; -public interface DataConsumerService extends DataBrokerService { +public interface DataProviderService extends DataBrokerService { /** * Adds {@link DataValidator} for specified Data Store diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java index b9f5d5aa27..4b01aed6ee 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-api/src/main/java/org/opendaylight/controller/sal/binding/api/data/RuntimeDataProvider.java @@ -2,9 +2,50 @@ package org.opendaylight.controller.sal.binding.api.data; import java.util.Set; +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.DataRoot; public interface RuntimeDataProvider { + Set getSupportedStores(); + + Set> getProvidedDataRoots(); + + + /** + * Returns a data from specified Data Store. + * + * Returns all the data visible to the consumer from specified Data Store. + * + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, from which will be data retrieved + * @return data visible to the consumer + */ + T getData(DataStoreIdentifier store, Class rootType); + + /** + * Returns a filtered subset of data from specified Data Store. + * + *

    + * The filter is modeled as an hierarchy of Java TOs starting with + * implementation of {@link DataRoot} representing data root. The semantics + * of the filter tree is the same as filter semantics defined in the NETCONF + * protocol for rpc operations get and get-config + * in Section 6 of RFC6241. + * + * + * @see http://tools.ietf.org/html/rfc6241#section-6 + * @param + * Interface generated from YANG module representing root of data + * @param store + * Identifier of the store, from which will be data retrieved + * @param filter + * Data tree filter similar to the NETCONF filter + * @return + */ + T getData(DataStoreIdentifier store, T filter); } diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/.gitignore b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/.gitignore new file mode 100644 index 0000000000..04b73cb01e --- /dev/null +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/.gitignore @@ -0,0 +1 @@ +/xtend-gen diff --git a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend index 74ef87ae5a..4f7d41a12c 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend +++ b/opendaylight/sal/yang-prototype/sal/sal-binding-broker-impl/src/main/java/org/opendaylight/controller/sal/binding/impl/BindingAwareBrokerImpl.xtend @@ -38,7 +38,8 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { private Map, RpcProxyContext> managedProxies = new HashMap(); private var NotificationBrokerImpl notifyBroker private var ServiceRegistration notifyBrokerRegistration - + private var DataBrokerImpl dataBroker + @Property var BundleContext brokerBundleContext @@ -80,6 +81,17 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { new OsgiProviderContext(providerCtx, this) } + /** + * Returns a Managed Direct Proxy for supplied class + * + * Managed direct proxy is a generated proxy class conforming to the supplied interface + * which delegates all calls to the backing delegate. + * + * Proxy does not do any validation, null pointer checks or modifies data in any way, it + * is only use to avoid exposing direct references to backing implementation of service. + * + * If proxy class does not exist for supplied service class it will be generated automatically. + */ def getManagedDirectProxy(Class service) { var RpcProxyContext existing = null @@ -115,6 +127,10 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { return proxyCls.toClass(delegate.classLoader) } + /** + * Registers RPC Implementation + * + */ def registerRpcImplementation(Class type, T service, OsgiProviderContext context, Hashtable properties) { val proxy = getManagedDirectProxy(type) @@ -126,12 +142,26 @@ class BindingAwareBrokerImpl implements BindingAwareBroker { return new RpcServiceRegistrationImpl(type, service, osgiReg); } + /** + * Helper method to return delegate from ManagedDirectedProxy with use of reflection. + * + * Note: This method uses reflection, but access to delegate field should be + * avoided and called only if neccessary. + * + */ def getDelegate(RpcService proxy) { val field = proxy.class.getField(DELEGATE_FIELD) if(field == null) throw new UnsupportedOperationException("Unable to get delegate from proxy"); return field.get(proxy) as T } + /** + * Helper method to set delegate to ManagedDirectedProxy with use of reflection. + * + * Note: This method uses reflection, but setting delegate field should not occur too much + * to introduce any significant performance hits. + * + */ def void setDelegate(RpcService proxy, RpcService delegate) { val field = proxy.class.getField(DELEGATE_FIELD) if(field == null) throw new UnsupportedOperationException("Unable to set delegate to proxy"); diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml b/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml index e3ded1a679..15e90ec8c5 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/pom.xml @@ -1,27 +1,27 @@ - - 4.0.0 - - org.opendaylight.controller - sal-parent - 1.0-SNAPSHOT - - sal-core-api - - - - org.opendaylight.controller - sal-common - 1.0-SNAPSHOT - - - - org.opendaylight.controller - yang-data-api - - - org.opendaylight.controller - yang-model-api - - + + 4.0.0 + + org.opendaylight.controller + sal-parent + 1.0-SNAPSHOT + + sal-core-api + + + + org.opendaylight.controller + sal-common + 1.0-SNAPSHOT + + + + org.opendaylight.yangtools + yang-data-api + + + org.opendaylight.yangtools + yang-model-api + + \ No newline at end of file diff --git a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java index f4bc71142a..fef894ba5c 100644 --- a/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java +++ b/opendaylight/sal/yang-prototype/sal/sal-core-api/src/main/java/org/opendaylight/controller/sal/core/api/data/DataBrokerService.java @@ -16,7 +16,7 @@ import org.opendaylight.controller.sal.core.api.Consumer; import org.opendaylight.controller.sal.core.api.Provider; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.CompositeNodeModification; +import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode; import org.opendaylight.yangtools.yang.data.api.Node; @@ -106,7 +106,7 @@ public interface DataBrokerService extends BrokerService { * was successful, otherwise list of the encountered errors. */ RpcResult editCandidateData(DataStoreIdentifier store, - CompositeNodeModification changeSet); + MutableCompositeNode changeSet); /** * Initiates a two-phase commit of candidate data. diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java index 71ef68d565..0a73110262 100644 --- a/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-consumer/src/main/java/org/opendaylight/controller/sample/toaster/provider/impl/ToastConsumerImpl.java @@ -11,15 +11,21 @@ import java.util.Dictionary; import java.util.Hashtable; import java.util.concurrent.ExecutionException; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; +import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareConsumer; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; import org.opendaylight.controller.sal.binding.api.NotificationListener; import org.opendaylight.controller.sal.binding.api.NotificationService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; +import org.opendaylight.controller.sal.binding.api.data.DataBrokerService; +import org.opendaylight.controller.sal.common.DataStoreIdentifier; +import org.opendaylight.controller.sal.common.GlobalDataStore; import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.MakeToastInputBuilder; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastDone; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToastType; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.Toaster; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterData; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService; import org.opendaylight.yangtools.yang.common.RpcResult; import org.osgi.framework.BundleActivator; @@ -28,7 +34,7 @@ import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ToastConsumerImpl implements BundleActivator, BindingAwareConsumer, ToastConsumer, +public class ToastConsumerImpl extends AbstractBindingAwareConsumer implements BundleActivator, BindingAwareConsumer, ToastConsumer, NotificationListener { private static final Logger log = LoggerFactory.getLogger(ToastConsumerImpl.class); @@ -64,22 +70,17 @@ public class ToastConsumerImpl implements BundleActivator, BindingAwareConsumer, this.session = session; NotificationService notificationService = session.getSALService(NotificationService.class); notificationService.addNotificationListener(ToastDone.class, this); - - } - - @Override - public void start(BundleContext context) throws Exception { - ServiceReference brokerRef = context.getServiceReference(BindingAwareBroker.class); - BindingAwareBroker broker = context.getService(brokerRef); - broker.registerConsumer(this, context); - Dictionary properties = new Hashtable<>(); - context.registerService(ToastConsumer.class, this, properties); + + } - @Override - public void stop(BundleContext context) throws Exception { - // TODO Auto-generated method stub - + private void loadToasterData() { + // We request data store service implementation + DataBrokerService brokerService = session.getSALService(DataBrokerService.class); + + ToasterData data = brokerService.getData(GlobalDataStore.RuntimeInfo, ToasterData.class); + Toaster toaster = data.getToaster(); + log.info("Available toaster is: ", toaster.getToasterManufacturer(),toaster.getToasterModelNumber()); } @Override diff --git a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java index 08ac1494c6..c776f363dd 100644 --- a/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java +++ b/opendaylight/sal/yang-prototype/sal/samples/toaster-provider/src/main/java/org/opendaylight/controller/sample/toaster/provider/ToasterProvider.java @@ -3,11 +3,12 @@ import java.util.Collection; import java.util.Collections; +import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev20091120.ToasterService; import org.opendaylight.yangtools.yang.binding.RpcService; import org.osgi.framework.BundleActivator; @@ -17,7 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ToasterProvider implements BindingAwareProvider, BundleActivator { +public class ToasterProvider extends AbstractBindingAwareProvider { private static final Logger log = LoggerFactory.getLogger(ToasterProvider.class); private ConsumerContext consumerContext; @@ -55,17 +56,4 @@ public class ToasterProvider implements BindingAwareProvider, BundleActivator { public Collection getFunctionality() { return Collections.emptySet(); } - - @Override - public void start(BundleContext context) throws Exception { - ServiceReference brokerRef = context.getServiceReference(BindingAwareBroker.class); - BindingAwareBroker broker = context.getService(brokerRef); - broker.registerProvider(this, context); - } - - @Override - public void stop(BundleContext context) throws Exception { - - - } }