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.test.tool.monitoring;
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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.extension.rev131210.Session1;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.sessions.Session;
16 import org.opendaylight.yangtools.yang.common.QName;
18 final class MonitoringSession {
21 private Session managementSession;
23 MonitoringSession(final Session managementSession) {
24 this.managementSession = managementSession;
30 public void setManagementSession(final Session managementSession) {
31 this.managementSession = managementSession;
34 @XmlElement(name = "session-id")
36 return managementSession.getSessionId().longValue();
39 @XmlElement(name = "source-host")
40 public String getSourceHost() {
41 final IpAddress ipAddress = managementSession.getSourceHost().getIpAddress();
42 if (ipAddress.getIpv4Address() != null) {
43 return ipAddress.getIpv4Address().getValue();
45 return ipAddress.getIpv6Address().getValue();
49 @XmlElement(name = "login-time")
50 public String getLoginTime() {
51 return managementSession.getLoginTime().getValue();
54 @XmlElement(name = "in-bad-rpcs")
55 public Long getInBadRpcs() {
56 return managementSession.getInBadRpcs().getValue().longValue();
59 @XmlElement(name = "in-rpcs")
60 public Long getInRpcs() {
61 return managementSession.getInRpcs().getValue().longValue();
64 @XmlElement(name = "out-notifications")
65 public Long getOutNotifications() {
66 return managementSession.getOutNotifications().getValue().longValue();
69 @XmlElement(name = "out-rpc-errors")
70 public Long getOutRpcErrors() {
71 return managementSession.getOutRpcErrors().getValue().longValue();
74 @XmlElement(name = "transport")
75 public String getTransport() {
77 final QName qualifiedName = (QName) managementSession.getTransport().getField("QNAME").get(null);
78 // Add extension prefix if transport type is from extension yang module
79 if (qualifiedName.getNamespace().toString().equals(MonitoringConstants.EXTENSION_NAMESPACE)) {
80 return Joiner.on(':').join(MonitoringConstants.EXTENSION_NAMESPACE_PREFIX,
81 qualifiedName.getLocalName());
83 return qualifiedName.getLocalName();
85 } catch (final NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
86 throw new IllegalArgumentException("Unknown transport type " + managementSession.getTransport(), e);
90 @XmlElement(name = "session-identifier", namespace = MonitoringConstants.EXTENSION_NAMESPACE)
91 public String getSessionType() {
92 return managementSession.augmentation(Session1.class).getSessionIdentifier();
95 @XmlElement(name = "username")
96 public String getUsername() {
97 return managementSession.getUsername();