blob: 1f6946a128e341b978e6a0b39ca9515c68458535 [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 HIGUCHI4bfdd532014-02-07 13:47:36 -08003import java.util.Collections;
4import java.util.HashSet;
5import java.util.Set;
6
Jonathan Hart25bd53e2014-04-30 23:44:09 -07007import net.onrc.onos.core.util.SwitchPort;
8
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -08009/**
10 * Port Object stored in In-memory Topology.
Ray Milkey269ffb92014-04-03 14:43:30 -070011 * <p/>
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080012 * TODO REMOVE following design memo: This object itself may hold the DBObject,
13 * but this Object itself will not issue any read/write to the DataStore.
14 */
Jonathan Hart062a2e82014-02-03 09:41:57 -080015public class PortImpl extends NetworkGraphObject implements Port {
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080016
Ray Milkey269ffb92014-04-03 14:43:30 -070017 private Switch sw;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080018
Ray Milkey269ffb92014-04-03 14:43:30 -070019 private Long number;
20 private String description;
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080021
Jonathan Hart25bd53e2014-04-30 23:44:09 -070022 private final SwitchPort switchPort;
23
Ray Milkey269ffb92014-04-03 14:43:30 -070024 // These needs to be ConcurrentCollecton if allowing Graph to be accessed Concurrently
25 protected Set<Device> devices;
Jonathan Hart062a2e82014-02-03 09:41:57 -080026
Ray Milkey269ffb92014-04-03 14:43:30 -070027 public PortImpl(NetworkGraph graph, Switch parentSwitch, Long number) {
28 super(graph);
29 this.sw = parentSwitch;
30 this.number = number;
31 this.devices = new HashSet<>();
Jonathan Hart25bd53e2014-04-30 23:44:09 -070032
33 switchPort = new SwitchPort(parentSwitch.getDpid(), number.shortValue());
Ray Milkey269ffb92014-04-03 14:43:30 -070034 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080035
Ray Milkey269ffb92014-04-03 14:43:30 -070036 @Override
37 public Long getDpid() {
38 return sw.getDpid();
39 }
Yuta HIGUCHIea516d62014-02-13 15:59:32 -080040
Ray Milkey269ffb92014-04-03 14:43:30 -070041 @Override
42 public Long getNumber() {
43 return number;
44 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080045
Ray Milkey269ffb92014-04-03 14:43:30 -070046 @Override
Jonathan Hart25bd53e2014-04-30 23:44:09 -070047 public SwitchPort asSwitchPort() {
48 return switchPort;
49 }
50
51 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070052 public String getDescription() {
53 return description;
54 }
Yuta HIGUCHIc0366272014-02-10 21:04:57 -080055
Ray Milkey269ffb92014-04-03 14:43:30 -070056 public void setDescription(String description) {
57 this.description = description;
58 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080059
Ray Milkey269ffb92014-04-03 14:43:30 -070060 @Override
61 public Long getHardwareAddress() {
62 // TODO Auto-generated method stub
63 return 0L;
64 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 @Override
67 public Switch getSwitch() {
68 return sw;
69 }
Yuta HIGUCHI181d34d2014-02-05 15:05:46 -080070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 @Override
72 public Link getOutgoingLink() {
Jonathan Hart25bd53e2014-04-30 23:44:09 -070073 return graph.getOutgoingLink(switchPort.dpid().value(),
74 (long) switchPort.port().value());
Ray Milkey269ffb92014-04-03 14:43:30 -070075 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080076
Ray Milkey269ffb92014-04-03 14:43:30 -070077 @Override
78 public Link getIncomingLink() {
Jonathan Hart25bd53e2014-04-30 23:44:09 -070079 return graph.getIncomingLink(switchPort.dpid().value(),
80 (long) switchPort.port().value());
Ray Milkey269ffb92014-04-03 14:43:30 -070081 }
Jonathan Hart062a2e82014-02-03 09:41:57 -080082
Ray Milkey269ffb92014-04-03 14:43:30 -070083 @Override
84 public Iterable<Device> getDevices() {
85 return Collections.unmodifiableSet(this.devices);
86 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080087
Ray Milkey269ffb92014-04-03 14:43:30 -070088 /**
89 * @param d
90 * @return true if successfully added
91 */
92 public boolean addDevice(Device d) {
93 return this.devices.add(d);
94 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -080095
Ray Milkey269ffb92014-04-03 14:43:30 -070096 /**
97 * @param d
98 * @return true if device existed and was removed
99 */
100 public boolean removeDevice(Device d) {
101 return this.devices.remove(d);
102 }
Yuta HIGUCHI4bfdd532014-02-07 13:47:36 -0800103
Ray Milkey269ffb92014-04-03 14:43:30 -0700104 public void removeAllDevice() {
105 this.devices.clear();
106 }
Yuta HIGUCHIcd922f42014-02-11 18:59:11 -0800107
Ray Milkey269ffb92014-04-03 14:43:30 -0700108 @Override
109 public String toString() {
110 return String.format("%d:%d",
111 getSwitch().getDpid(),
112 getNumber());
113 }
Jonathan Hart062a2e82014-02-03 09:41:57 -0800114}