Skip to content

Commit 99c2095

Browse files
author
Kostiantyn Karakata
committed
ODLC-954: Added model for Device.
1 parent 2782b62 commit 99c2095

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module device {
2+
namespace "urn:opendaylight:params:xml:ns:yang:device";
3+
prefix "device";
4+
yang-version 1.1;
5+
6+
organization "Pantheon Tech";
7+
contact "[email protected]";
8+
description "YANG model for a network device.";
9+
10+
revision "2025-06-11" {
11+
description "Initial version with MAC address, IP address, and hostname.";
12+
}
13+
14+
typedef mac-address {
15+
type string {
16+
pattern '([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}';
17+
}
18+
description "MAC address in the format XX:XX:XX:XX:XX:XX.";
19+
}
20+
21+
typedef ipv4-address {
22+
type string {
23+
pattern
24+
'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}'
25+
+ '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)';
26+
}
27+
description "IPv4 address in dotted decimal notation.";
28+
}
29+
30+
container device {
31+
description "Represents a network device.";
32+
33+
leaf hostname {
34+
type string;
35+
description "The hostname of the device.";
36+
}
37+
38+
leaf mac-address {
39+
type mac-address;
40+
description "The MAC address of the device.";
41+
}
42+
43+
leaf ip-address {
44+
type ipv4-address;
45+
description "The IPv4 address assigned to the device.";
46+
}
47+
48+
leaf location {
49+
type string;
50+
description "Physical or logical location of the device.";
51+
}
52+
}
53+
}

mock-binding-project/impl/src/main/java/pt/impl/MockBindingProvider.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@
77
*/
88
package pt.impl;
99

10+
import com.google.common.util.concurrent.FluentFuture;
11+
import java.net.UnknownHostException;
12+
import java.util.Optional;
13+
import java.util.concurrent.ExecutionException;
1014
import org.opendaylight.mdsal.binding.api.DataBroker;
15+
import org.opendaylight.mdsal.binding.api.ReadTransaction;
16+
import org.opendaylight.mdsal.binding.api.WriteTransaction;
17+
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.Device;
19+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.DeviceBuilder;
20+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.Ipv4Address;
21+
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.device.rev250611.MacAddress;
22+
import org.opendaylight.yangtools.binding.DataObjectIdentifier;
1123
import org.slf4j.Logger;
1224
import org.slf4j.LoggerFactory;
1325

@@ -24,8 +36,23 @@ public MockBindingProvider(final DataBroker dataBroker) {
2436
/**
2537
* Method called when the blueprint container is created.
2638
*/
27-
public void init() {
39+
public void init() throws ExecutionException, InterruptedException, UnknownHostException {
2840
LOG.info("MockBindingProvider Session Initiated");
41+
Device data = new DeviceBuilder().setHostname("Host1")
42+
.setIpAddress(Ipv4Address.getDefaultInstance("156.127.13.51"))
43+
.setMacAddress(MacAddress.getDefaultInstance("00:1A:2B:3C:4D:5E"))
44+
.setLocation("EU")
45+
.build();
46+
47+
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
48+
DataObjectIdentifier<Device> identifier = DataObjectIdentifier.builder(Device.class).build();
49+
tx.put(LogicalDatastoreType.CONFIGURATION, identifier, data);
50+
tx.commit().get();
51+
52+
final ReadTransaction rx = dataBroker.newReadOnlyTransaction();
53+
FluentFuture<Optional<Device>> future = rx.read(LogicalDatastoreType.CONFIGURATION, identifier);
54+
Device dataOut = future.get().orElseThrow();
55+
LOG.info("Data Out is {}", dataOut);
2956
}
3057

3158
/**

mock-binding-project/karaf/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
<type>xml</type>
5858
<scope>runtime</scope>
5959
</dependency>
60+
61+
<dependency>
62+
<groupId>org.opendaylight.netconf</groupId>
63+
<artifactId>odl-restconf-nb</artifactId>
64+
<version>8.0.7</version>
65+
<classifier>features</classifier>
66+
<type>xml</type>
67+
<scope>runtime</scope>
68+
</dependency>
6069
</dependencies>
6170

6271
</project>

0 commit comments

Comments
 (0)