diff --git a/mock-binding-project/api/src/main/yang/device.yang b/mock-binding-project/api/src/main/yang/device.yang new file mode 100644 index 0000000..160784b --- /dev/null +++ b/mock-binding-project/api/src/main/yang/device.yang @@ -0,0 +1,53 @@ +module device { + namespace "urn:opendaylight:params:xml:ns:yang:device"; + prefix "device"; + yang-version 1.1; + + organization "Pantheon Tech"; + contact "kostiantyn.karakata@pantheon.tech"; + description "YANG model for a network device."; + + revision "2025-06-11" { + description "Initial version with MAC address, IP address, and hostname."; + } + + typedef mac-address { + type string { + pattern '([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}'; + } + description "MAC address in the format XX:XX:XX:XX:XX:XX."; + } + + typedef ipv4-address { + type string { + pattern + '((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}' + + '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'; + } + description "IPv4 address in dotted decimal notation."; + } + + container device { + description "Represents a network device."; + + leaf hostname { + type string; + description "The hostname of the device."; + } + + leaf mac-address { + type mac-address; + description "The MAC address of the device."; + } + + leaf ip-address { + type ipv4-address; + description "The IPv4 address assigned to the device."; + } + + leaf location { + type string; + description "Physical or logical location of the device."; + } + } +} diff --git a/mock-binding-project/impl/src/main/java/pt/impl/MockBindingProvider.java b/mock-binding-project/impl/src/main/java/pt/impl/MockBindingProvider.java index 734e93c..4452d89 100644 --- a/mock-binding-project/impl/src/main/java/pt/impl/MockBindingProvider.java +++ b/mock-binding-project/impl/src/main/java/pt/impl/MockBindingProvider.java @@ -7,7 +7,19 @@ */ package pt.impl; +import com.google.common.util.concurrent.FluentFuture; +import java.net.UnknownHostException; +import java.util.Optional; +import java.util.concurrent.ExecutionException; import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.binding.api.WriteTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.Device; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.DeviceBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.MacAddress; +import org.opendaylight.yangtools.binding.DataObjectIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,8 +36,23 @@ public MockBindingProvider(final DataBroker dataBroker) { /** * Method called when the blueprint container is created. */ - public void init() { + public void init() throws ExecutionException, InterruptedException, UnknownHostException { LOG.info("MockBindingProvider Session Initiated"); + Device data = new DeviceBuilder().setHostname("Host1") + .setIpAddress(Ipv4Address.getDefaultInstance("156.127.13.51")) + .setMacAddress(MacAddress.getDefaultInstance("00:1A:2B:3C:4D:5E")) + .setLocation("EU") + .build(); + + final WriteTransaction tx = dataBroker.newWriteOnlyTransaction(); + DataObjectIdentifier identifier = DataObjectIdentifier.builder(Device.class).build(); + tx.put(LogicalDatastoreType.CONFIGURATION, identifier, data); + tx.commit().get(); + + final ReadTransaction rx = dataBroker.newReadOnlyTransaction(); + FluentFuture> future = rx.read(LogicalDatastoreType.CONFIGURATION, identifier); + Device dataOut = future.get().orElseThrow(); + LOG.info("Data Out is {}", dataOut); } /** diff --git a/mock-binding-project/karaf/pom.xml b/mock-binding-project/karaf/pom.xml index 88c0fc8..f787e04 100644 --- a/mock-binding-project/karaf/pom.xml +++ b/mock-binding-project/karaf/pom.xml @@ -57,6 +57,15 @@ xml runtime + + + org.opendaylight.netconf + odl-restconf-nb + 8.0.7 + features + xml + runtime +