Toshio Koide | 5f26065 | 2014-01-30 14:41:12 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.app; |
| 2 | |
| 3 | import java.util.Collection; |
| 4 | import java.util.HashSet; |
| 5 | |
| 6 | /** |
| 7 | * This code is valid for the architectural study purpose only. |
| 8 | * Base class for Link representation |
| 9 | * |
| 10 | * @author Toshio Koide (t-koide@onlab.us) |
| 11 | * |
| 12 | */ |
| 13 | public class Link extends NetworkGraphEntity { |
| 14 | protected SwitchPort srcPort; |
| 15 | protected SwitchPort dstPort; |
| 16 | protected HashSet<Flow> flows; |
| 17 | protected Double capacity; |
| 18 | |
| 19 | public Link(SwitchPort srcPort, SwitchPort dstPort) { |
| 20 | super(srcPort.getNetworkGraph()); |
| 21 | this.srcPort = srcPort; |
| 22 | this.dstPort = dstPort; |
| 23 | this.flows = new HashSet<Flow>(); |
| 24 | this.capacity = Double.POSITIVE_INFINITY; |
| 25 | setToPorts(); |
| 26 | } |
| 27 | |
| 28 | public void setToPorts() { |
| 29 | srcPort.setOutgoingLink(this); |
| 30 | dstPort.setIncomingLink(this); |
| 31 | } |
| 32 | |
| 33 | public void unsetFromPorts() { |
| 34 | srcPort.setOutgoingLink(null); |
| 35 | dstPort.setIncomingLink(null); |
| 36 | } |
| 37 | |
| 38 | public void setCapacity(Double capacity) { |
| 39 | this.capacity = capacity; |
| 40 | } |
| 41 | |
| 42 | public Double getCapacity() { |
| 43 | return capacity; |
| 44 | } |
| 45 | |
| 46 | public boolean addFlow(Flow flow) { |
| 47 | return flows.add(flow); |
| 48 | } |
| 49 | |
| 50 | public boolean removeFlow(Flow flow) { |
| 51 | return flows.remove(flow); |
| 52 | } |
| 53 | |
| 54 | public Collection<Flow> getFlows() { |
| 55 | return flows; |
| 56 | } |
| 57 | |
| 58 | public SwitchPort getSrcPort() { |
| 59 | return srcPort; |
| 60 | } |
| 61 | |
| 62 | public SwitchPort getDstPort() { |
| 63 | return dstPort; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public String toString() { |
| 68 | return String.format("%s --(%f Mbps, %d flows)--> %s", |
| 69 | getSrcPort().toString(), |
| 70 | getCapacity(), |
| 71 | getFlows().size(), |
| 72 | getDstPort().toString()); |
| 73 | } |
| 74 | } |