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.protocol.bgp.linkstate;
10 import java.util.Collections;
14 import org.opendaylight.protocol.bgp.linkstate.ISISAreaIdentifier;
15 import org.opendaylight.protocol.bgp.linkstate.RouterIdentifier;
16 import org.opendaylight.protocol.bgp.linkstate.TopologyIdentifier;
17 import org.opendaylight.protocol.bgp.linkstate.TopologyNodeInformation;
18 import com.google.common.base.CharMatcher;
19 import com.google.common.base.Objects.ToStringHelper;
20 import com.google.common.base.Preconditions;
23 * A single (router) node in the network topology. Nodes are interconnected by links and have a bunch of attributes. One
24 * of the key attributes is the set of prefixes for which this node acts as a network edge router.
26 public class NetworkNodeState extends NetworkObjectState {
27 public static final NetworkNodeState EMPTY = new NetworkNodeState();
28 private static final long serialVersionUID = 1L;
29 private Map<TopologyIdentifier, TopologyNodeInformation> topologyMembership;
30 private Set<ISISAreaIdentifier> areaMembership;
31 private boolean areaBorderRouter;
32 private boolean external;
33 private Set<RouterIdentifier> identifierAlternatives;
34 private String dynamicHostName;
36 private NetworkNodeState() {
37 this(NetworkObjectState.EMPTY, Collections.<TopologyIdentifier, TopologyNodeInformation> emptyMap(), Collections.<ISISAreaIdentifier> emptySet(), false, false, Collections.<RouterIdentifier> emptySet(), null);
40 public NetworkNodeState(final NetworkObjectState orig, final Map<TopologyIdentifier, TopologyNodeInformation> topologyMembership,
41 final Set<ISISAreaIdentifier> areaMembership, final boolean areaBorderRouter, final boolean external,
42 final Set<RouterIdentifier> identifierAlternatives, final String dynamicHostName) {
44 Preconditions.checkNotNull(areaMembership);
45 Preconditions.checkNotNull(identifierAlternatives);
46 Preconditions.checkNotNull(topologyMembership);
47 this.topologyMembership = topologyMembership;
48 this.areaMembership = areaMembership;
49 this.areaBorderRouter = areaBorderRouter;
50 this.external = external;
51 this.identifierAlternatives = identifierAlternatives;
52 this.dynamicHostName = dynamicHostName;
55 protected NetworkNodeState(final NetworkNodeState orig) {
57 this.topologyMembership = orig.topologyMembership;
58 this.areaMembership = orig.areaMembership;
59 this.areaBorderRouter = orig.areaBorderRouter;
60 this.external = orig.external;
61 this.identifierAlternatives = orig.identifierAlternatives;
62 this.dynamicHostName = orig.dynamicHostName;
66 * Get the per-topology information about this node.
68 * @return An immutable map of per-topology state information
70 public final Map<TopologyIdentifier, TopologyNodeInformation> getTopologyMembership() {
71 return this.topologyMembership;
74 public final NetworkNodeState withTopologyMembership(final Map<TopologyIdentifier, TopologyNodeInformation> topologyMembership) {
75 final NetworkNodeState ret = newInstance();
76 ret.topologyMembership = Collections.unmodifiableMap(topologyMembership);
81 * Get area membership information.
83 * @return An immutable set containing identifiers of all node area this node is member of.
85 public final Set<ISISAreaIdentifier> getAreaMembership() {
86 return this.areaMembership;
89 public final NetworkNodeState withAreaMembership(final Set<ISISAreaIdentifier> areaMembership) {
90 final NetworkNodeState ret = newInstance();
91 ret.areaMembership = Collections.unmodifiableSet(areaMembership);
96 * Get ABR flag value. Area Border Routers (e.g. routers connected to multiple areas) advertise this flag.
98 * @return True if this router is an ABR.
100 public final boolean isAreaBorderRouter() {
101 return this.areaBorderRouter;
104 public final NetworkNodeState withAreaBorderRouter(final boolean value) {
105 final NetworkNodeState ret = newInstance();
106 ret.areaBorderRouter = value;
111 * Get external flag value. This corresponds to <a href="http://tools.ietf.org/html/rfc2328">RFC 2328</a> definition
112 * of ExternalRoutingCapability. It is advertized by all routers connected to external ASes.
114 * @return True if the router is an AS-border router
116 public final boolean isExternal() {
117 return this.external;
120 public final NetworkNodeState withExternal(final boolean value) {
121 final NetworkNodeState ret = newInstance();
122 ret.external = value;
127 * http://tools.ietf.org/html/rfc5301#section-3, encoded as a String. The string is guaranteed to contain US-ASCII
130 * @return dynamic hostname of the router that is connected
132 public final String getDynamicHostname() {
133 return this.dynamicHostName;
136 public final NetworkNodeState withDynamicHostname(final String value) {
137 Preconditions.checkNotNull(value);
138 Preconditions.checkArgument(value.length() >= 1);
139 Preconditions.checkArgument(value.length() <= 255);
140 Preconditions.checkArgument(CharMatcher.ASCII.matchesAllOf(value));
142 final NetworkNodeState ret = newInstance();
143 ret.dynamicHostName = value;
148 * Return the set of alternative identifiers to which this node responds. This set must contain the primary
151 * @return set of identifier alternatives.
153 public final Set<RouterIdentifier> getIdentifierAlternatives() {
154 return this.identifierAlternatives;
157 public final NetworkNodeState withIdentifierAlternatives(final Set<RouterIdentifier> identifierAlternatives) {
158 final NetworkNodeState ret = newInstance();
159 ret.identifierAlternatives = identifierAlternatives;
164 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
165 toStringHelper.add("topologyMembership", this.topologyMembership);
166 toStringHelper.add("areaMembership", this.areaMembership);
167 toStringHelper.add("external", this.external);
168 toStringHelper.add("ABR", this.areaBorderRouter);
169 toStringHelper.add("dynamicHostname", this.dynamicHostName);
170 toStringHelper.add("routerIdentifiers", this.identifierAlternatives);
171 return super.addToStringAttributes(toStringHelper);
175 protected NetworkNodeState newInstance() {
176 return new NetworkNodeState(this);