blob: 281df21d8094eb63bc23dd8bfd4d3c0735697d34 [file] [log] [blame]
Jonathan Hart472062d2014-04-03 10:56:48 -07001package net.onrc.onos.core.topology;
Jonathan Hart062a2e82014-02-03 09:41:57 -08002
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -07003import java.util.Map;
4
Yuta HIGUCHI02ccb8c2014-07-10 11:29:45 -07005import net.onrc.onos.core.util.LinkTuple;
Pavlin Radoslavova5637c02014-07-30 15:55:11 -07006import static com.google.common.base.Preconditions.checkNotNull;
Jonathan Hart25bd53e2014-04-30 23:44:09 -07007
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08008/**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -07009 * Handler to Link object stored in In-memory Topology snapshot.
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080010 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070011public class LinkImpl extends TopologyObject implements Link {
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080012
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070013 private final LinkTuple id;
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070014
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070015
Ray Milkey269ffb92014-04-03 14:43:30 -070016 /**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070017 * Creates a Link handler object.
Ray Milkey269ffb92014-04-03 14:43:30 -070018 *
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070019 * @param topology Topology instance this object belongs to
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070020 * @param linkTuple Link identifier
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070021 */
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070022 LinkImpl(BaseInternalTopology topology, LinkTuple linkTuple) {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070023 super(topology);
Pavlin Radoslavova5637c02014-07-30 15:55:11 -070024 this.id = checkNotNull(linkTuple);
Ray Milkey269ffb92014-04-03 14:43:30 -070025 }
Toshio Koide2f570c12014-02-06 16:55:32 -080026
Ray Milkey269ffb92014-04-03 14:43:30 -070027 @Override
Yuta HIGUCHI02ccb8c2014-07-10 11:29:45 -070028 public LinkTuple getLinkTuple() {
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070029 return id;
Yuta HIGUCHI02ccb8c2014-07-10 11:29:45 -070030 }
31
32 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070033 public Switch getSrcSwitch() {
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070034 // TODO Cache BaseTopologyAdaptor instance?
35 return new BaseTopologyAdaptor(topology).getSwitch(id.getSrc().getDpid());
Ray Milkey269ffb92014-04-03 14:43:30 -070036 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080037
Ray Milkey269ffb92014-04-03 14:43:30 -070038 @Override
39 public Port getSrcPort() {
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070040 return new BaseTopologyAdaptor(topology).getPort(id.getSrc());
Ray Milkey269ffb92014-04-03 14:43:30 -070041 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080042
Ray Milkey269ffb92014-04-03 14:43:30 -070043 @Override
44 public Switch getDstSwitch() {
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070045 return new BaseTopologyAdaptor(topology).getSwitch(id.getDst().getDpid());
Ray Milkey269ffb92014-04-03 14:43:30 -070046 }
Pavlin Radoslavov7c8f69a2014-02-19 19:01:45 -080047
Ray Milkey269ffb92014-04-03 14:43:30 -070048 @Override
49 public Port getDstPort() {
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070050 return new BaseTopologyAdaptor(topology).getPort(id.getDst());
Ray Milkey269ffb92014-04-03 14:43:30 -070051 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080052
Ray Milkey269ffb92014-04-03 14:43:30 -070053 @Override
54 public long getLastSeenTime() {
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -070055 throw new UnsupportedOperationException("Not implemented yet");
Ray Milkey269ffb92014-04-03 14:43:30 -070056 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080057
Ray Milkey269ffb92014-04-03 14:43:30 -070058 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070059 public Double getCapacity() {
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070060 return this.topology.getLinkData(id).getCapacity();
Ray Milkey269ffb92014-04-03 14:43:30 -070061 }
Toshio Koide0c9106d2014-02-19 15:26:38 -080062
Praseed Balakrishnanfa21be12014-07-15 14:42:26 -070063 /**
64 * Returns the link type of the link.
65 *
66 * @return {@link net.onrc.onos.core.topology.LinkType} for this link
67 */
68 @Override
69 public LinkType getLinkType() {
70 return LinkType.valueOf(getStringAttribute(TopologyElement.ELEMENT_TYPE,
71 LinkType.ETHERNET_LINK.toString()));
72 }
73
Ray Milkey269ffb92014-04-03 14:43:30 -070074 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070075 public String getStringAttribute(String attr) {
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070076 return this.topology.getLinkData(id).getStringAttribute(attr);
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070077 }
78
79 @Override
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070080 public String getStringAttribute(String attr, String def) {
81 final String v = getStringAttribute(attr);
82 if (v == null) {
83 return def;
84 } else {
85 return v;
86 }
87 }
88
89 @Override
90 public Map<String, String> getAllStringAttributes() {
Yuta HIGUCHI93d35ea2014-08-31 23:26:13 -070091 return this.topology.getLinkData(id).getAllStringAttributes();
Yuta HIGUCHIdb1b8302014-06-26 10:50:39 -070092 }
93
94 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070095 public String toString() {
96 return String.format("%s --(cap:%f Mbps)--> %s",
97 getSrcPort().toString(),
98 getCapacity(),
99 getDstPort().toString());
100 }
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -0700101
102
103 /**
104 * Returns the type of topology object.
105 *
106 * @return the type of the topology object
107 */
108 @Override
109 public String getType() {
Yuta HIGUCHIdbc33122014-07-10 13:32:32 -0700110 return getStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -0700111 }
Praseed Balakrishnan2aa6c0b2014-07-17 11:42:05 -0700112
113 /**
114 * Returns the config state of topology element.
115 *
116 * @return ConfigState
117 */
118 @Override
119 public ConfigState getConfigState() {
120 return ConfigState.valueOf(getStringAttribute(TopologyElement.ELEMENT_CONFIG_STATE));
121 }
122
123 /**
124 * Returns the status of topology element.
125 *
126 * @return AdminStatus
127 */
128 @Override
129 public AdminStatus getStatus() {
130 return AdminStatus.valueOf(getStringAttribute(TopologyElement.ELEMENT_ADMIN_STATUS));
131 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800132}