Merge "Simplify method isMutualExclusive in Subnet. Remove redundant 'if' statements."
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / messages / NetconfMessageAdditionalHeader.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.util.messages;
10
11 import com.google.common.base.Optional;
12 import com.google.common.base.Preconditions;
13
14 /**
15  * Additional header can be used with hello message to carry information about
16  * session's connection. Provided information can be reported via netconf
17  * monitoring.
18  * <pre>
19  * It has pattern "[username; host-address:port; transport; session-identifier;]"
20  * username - name of account on a remote
21  * host-address - client's IP address
22  * port - port number
23  * transport - tcp, ssh
24  * session-identifier - persister, client
25  * Session-identifier is optional, others mandatory.
26  * </pre>
27  */
28 public class NetconfMessageAdditionalHeader {
29
30     private static final String SC = ";";
31
32     public static String toString(String userName, String hostAddress, String port, String transport,
33             Optional<String> sessionIdentifier) {
34         Preconditions.checkNotNull(userName);
35         Preconditions.checkNotNull(hostAddress);
36         Preconditions.checkNotNull(port);
37         Preconditions.checkNotNull(transport);
38         String identifier = sessionIdentifier.isPresent() ? sessionIdentifier.get() : "";
39         return "[" + userName + SC + hostAddress + ":" + port + SC + transport + SC + identifier + SC + "]"
40                 + System.lineSeparator();
41     }
42 }