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.mdsal.binding.spec.naming.BindingMapping;
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().longValue();
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().longValue();
60 @XmlElement(name = "in-rpcs")
61 public Long getInRpcs() {
62 return managementSession.getInRpcs().getValue().longValue();
65 @XmlElement(name = "out-notifications")
66 public Long getOutNotifications() {
67 return managementSession.getOutNotifications().getValue().longValue();
70 @XmlElement(name = "out-rpc-errors")
71 public Long getOutRpcErrors() {
72 return managementSession.getOutRpcErrors().getValue().longValue();
75 @XmlElement(name = "transport")
76 public String getTransport() {
78 final QName qualifiedName = (QName) managementSession.getTransport().implementedInterface()
79 .getField(BindingMapping.QNAME_STATIC_FIELD_NAME).get(null);
80 // Add extension prefix if transport type is from extension yang module
81 if (qualifiedName.getNamespace().toString().equals(MonitoringConstants.EXTENSION_NAMESPACE)) {
82 return Joiner.on(':').join(MonitoringConstants.EXTENSION_NAMESPACE_PREFIX,
83 qualifiedName.getLocalName());
85 return qualifiedName.getLocalName();
87 } catch (final NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
88 throw new IllegalArgumentException("Unknown transport type " + managementSession.getTransport(), e);
92 @XmlElement(name = "session-identifier", namespace = MonitoringConstants.EXTENSION_NAMESPACE)
93 public String getSessionType() {
94 return managementSession.augmentation(Session1.class).getSessionIdentifier();
97 @XmlElement(name = "username")
98 public String getUsername() {
99 return managementSession.getUsername();