update NetworkGraph objects
- Use Object type instead of built-in
- Port number to Long
Change-Id: I30847b6cca801e58ca49dd9d1667cfd33a8ffb92
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/AbstractNetworkGraph.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/AbstractNetworkGraph.java
index 3fa4ad9..71ef16e 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/AbstractNetworkGraph.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/AbstractNetworkGraph.java
@@ -15,82 +15,99 @@
import org.slf4j.LoggerFactory;
public class AbstractNetworkGraph implements NetworkGraph {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory
- .getLogger(AbstractNetworkGraph.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(AbstractNetworkGraph.class);
- // DPID -> Switch
- protected ConcurrentMap<Long, Switch> switches;
+ // DPID -> Switch
+ protected ConcurrentMap<Long, Switch> switches;
- protected ConcurrentMap<InetAddress, Set<Device>> addr2Device;
- protected ConcurrentMap<MACAddress, Set<Device>> mac2Device;
+ protected ConcurrentMap<InetAddress, Set<Device>> addr2Device;
+ protected ConcurrentMap<MACAddress, Set<Device>> mac2Device;
- public AbstractNetworkGraph() {
- // TODO: Does these object need to be stored in Concurrent Collection?
- switches = new ConcurrentHashMap<>();
- addr2Device = new ConcurrentHashMap<>();
- mac2Device = new ConcurrentHashMap<>();
- }
-
- @Override
- public Switch getSwitch(long dpid) {
- // TODO Check if it is safe to directly return this Object.
- return switches.get(dpid);
- }
-
- @Override
- public Iterable<Switch> getSwitches() {
- // TODO Check if it is safe to directly return this Object.
- return Collections.unmodifiableCollection(switches.values());
- }
-
- @Override
- public Iterable<Link> getLinks() {
- List<Link> linklist = new LinkedList<>();
-
- for (Switch sw : switches.values()) {
- Iterable<Link> links = sw.getLinks();
- for (Link l : links) {
- linklist.add(l);
- }
+ public AbstractNetworkGraph() {
+ // TODO: Does these object need to be stored in Concurrent Collection?
+ switches = new ConcurrentHashMap<>();
+ addr2Device = new ConcurrentHashMap<>();
+ mac2Device = new ConcurrentHashMap<>();
}
- return linklist;
- }
- @Override
- public Iterable<Link> getLinksFromSwitch(long dpid) {
- Switch sw = getSwitch(dpid);
- if (sw == null) {
- return Collections.emptyList();
+ @Override
+ public Switch getSwitch(Long dpid) {
+ // TODO Check if it is safe to directly return this Object.
+ return switches.get(dpid);
}
- Iterable<Link> links = sw.getLinks();
- if (links instanceof Collection) {
- return Collections.unmodifiableCollection((Collection<Link>) links);
- } else {
- List<Link> linklist = new LinkedList<>();
- for (Link l : links) {
- linklist.add(l);
- }
- return linklist;
- }
- }
- @Override
- public Iterable<Device> getDeviceByIp(InetAddress ipAddress) {
- Set<Device> devices = addr2Device.get(ipAddress);
- if (devices == null) {
- return Collections.emptyList();
+ @Override
+ public Iterable<Switch> getSwitches() {
+ // TODO Check if it is safe to directly return this Object.
+ return Collections.unmodifiableCollection(switches.values());
}
- return Collections.unmodifiableCollection(devices);
- }
- @Override
- public Iterable<Device> getDeviceByMac(MACAddress address) {
- Set<Device> devices = mac2Device.get(address);
- if (devices == null) {
- return Collections.emptyList();
+ @Override
+ public Iterable<Link> getLinks() {
+ List<Link> linklist = new LinkedList<>();
+
+ for (Switch sw : switches.values()) {
+ Iterable<Link> links = sw.getOutgoingLinks();
+ for (Link l : links) {
+ linklist.add(l);
+ }
+ }
+ return linklist;
}
- return Collections.unmodifiableCollection(devices);
- }
+ @Override
+ public Iterable<Link> getOutgoingLinksFromSwitch(Long dpid) {
+ Switch sw = getSwitch(dpid);
+ if (sw == null) {
+ return Collections.emptyList();
+ }
+ Iterable<Link> links = sw.getOutgoingLinks();
+ if (links instanceof Collection) {
+ return Collections.unmodifiableCollection((Collection<Link>) links);
+ } else {
+ List<Link> linklist = new LinkedList<>();
+ for (Link l : links) {
+ linklist.add(l);
+ }
+ return linklist;
+ }
+ }
+
+ @Override
+ public Iterable<Link> getIncomingLinksFromSwitch(Long dpid) {
+ Switch sw = getSwitch(dpid);
+ if (sw == null) {
+ return Collections.emptyList();
+ }
+ Iterable<Link> links = sw.getIncomingLinks();
+ if (links instanceof Collection) {
+ return Collections.unmodifiableCollection((Collection<Link>) links);
+ } else {
+ List<Link> linklist = new LinkedList<>();
+ for (Link l : links) {
+ linklist.add(l);
+ }
+ return linklist;
+ }
+ }
+
+
+ @Override
+ public Iterable<Device> getDeviceByIp(InetAddress ipAddress) {
+ Set<Device> devices = addr2Device.get(ipAddress);
+ if (devices == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableCollection(devices);
+ }
+
+ @Override
+ public Iterable<Device> getDeviceByMac(MACAddress address) {
+ Set<Device> devices = mac2Device.get(address);
+ if (devices == null) {
+ return Collections.emptyList();
+ }
+ return Collections.unmodifiableCollection(devices);
+ }
}