2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.monitoring.xml.model;
10 import com.google.common.base.Joiner;
11 import javax.xml.bind.annotation.XmlElement;
12 import javax.xml.bind.annotation.XmlTransient;
13 import org.opendaylight.netconf.monitoring.MonitoringConstants;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210.Session1;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
17 import org.opendaylight.yangtools.yang.common.QName;
19 final class MonitoringSession {
22 private Session managementSession;
24 MonitoringSession(final Session managementSession) {
25 this.managementSession = managementSession;
31 public void setManagementSession(final Session managementSession) {
32 this.managementSession = managementSession;
35 @XmlElement(name = "session-id")
37 return managementSession.getSessionId();
40 @XmlElement(name = "source-host")
41 public String getSourceHost() {
42 final IpAddress ipAddress = managementSession.getSourceHost().getIpAddress();
43 if (ipAddress.getIpv4Address() != null) {
44 return ipAddress.getIpv4Address().getValue();
46 return ipAddress.getIpv6Address().getValue();
50 @XmlElement(name = "login-time")
51 public String getLoginTime() {
52 return managementSession.getLoginTime().getValue();
55 @XmlElement(name = "in-bad-rpcs")
56 public Long getInBadRpcs() {
57 return managementSession.getInBadRpcs().getValue();
60 @XmlElement(name = "in-rpcs")
61 public Long getInRpcs() {
62 return managementSession.getInRpcs().getValue();
65 @XmlElement(name = "out-notifications")
66 public Long getOutNotifications() {
67 return managementSession.getOutNotifications().getValue();
70 @XmlElement(name = "out-rpc-errors")
71 public Long getOutRpcErrors() {
72 return managementSession.getOutRpcErrors().getValue();
75 @XmlElement(name = "transport")
76 public String getTransport() {
78 QName qualifiedName = (QName) managementSession.getTransport().getField("QNAME").get(null);
79 // Add extension prefix if transport type is from extension yang module
80 if (qualifiedName.getNamespace().toString().equals(MonitoringConstants.EXTENSION_NAMESPACE)) {
81 return Joiner.on(':').join(MonitoringConstants.EXTENSION_NAMESPACE_PREFIX,
82 qualifiedName.getLocalName());
84 return qualifiedName.getLocalName();
86 } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
87 throw new IllegalArgumentException("Unknown transport type " + managementSession.getTransport(), e);
91 @XmlElement(name = "session-identifier", namespace = MonitoringConstants.EXTENSION_NAMESPACE)
92 public String getSessionType() {
93 return managementSession.augmentation(Session1.class).getSessionIdentifier();
96 @XmlElement(name = "username")
97 public String getUsername() {
98 return managementSession.getUsername();