Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions mock-binding-project/api/src/main/yang/device.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module device {
namespace "urn:opendaylight:params:xml:ns:yang:device";
prefix "device";
yang-version 1.1;

organization "Pantheon Tech";
contact "[email protected]";
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.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Device> identifier = DataObjectIdentifier.builder(Device.class).build();
tx.put(LogicalDatastoreType.CONFIGURATION, identifier, data);
tx.commit().get();

final ReadTransaction rx = dataBroker.newReadOnlyTransaction();
FluentFuture<Optional<Device>> future = rx.read(LogicalDatastoreType.CONFIGURATION, identifier);
Device dataOut = future.get().orElseThrow();
LOG.info("Data Out is {}", dataOut);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions mock-binding-project/karaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
<type>xml</type>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.opendaylight.netconf</groupId>
<artifactId>odl-restconf-nb</artifactId>
<version>8.0.7</version>
<classifier>features</classifier>
<type>xml</type>
<scope>runtime</scope>
</dependency>
</dependencies>

</project>
Loading