Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.networkgraph; |
| 2 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame] | 3 | import java.nio.ByteBuffer; |
| 4 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 5 | import net.onrc.onos.ofcontroller.networkgraph.PortEvent.SwitchPort; |
| 6 | |
| 7 | /** |
Yuta HIGUCHI | dac4caa | 2014-02-11 18:51:35 -0800 | [diff] [blame] | 8 | * Self-contained Link event Object |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 9 | * |
| 10 | * TODO: We probably want common base class/interface for Self-Contained Event Object |
| 11 | * |
| 12 | */ |
| 13 | public class LinkEvent { |
| 14 | private final SwitchPort src; |
| 15 | private final SwitchPort dst; |
| 16 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 17 | /** |
| 18 | * Default constructor. |
| 19 | */ |
| 20 | public LinkEvent() { |
| 21 | src = null; |
| 22 | dst = null; |
| 23 | } |
| 24 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 25 | public LinkEvent(Long src_dpid, Long src_port_no, Long dst_dpid, |
| 26 | Long dst_port_no) { |
| 27 | |
| 28 | src = new SwitchPort(src_dpid, src_port_no); |
| 29 | dst = new SwitchPort(dst_dpid, dst_port_no); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | public SwitchPort getSrc() { |
| 34 | return src; |
| 35 | } |
| 36 | |
| 37 | public SwitchPort getDst() { |
| 38 | return dst; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public String toString() { |
| 43 | return "[LinkEvent " + src + "->" + dst + "]"; |
| 44 | } |
| 45 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame] | 46 | public static final int LINKID_BYTES = 2 + PortEvent.PORTID_BYTES * 2; |
| 47 | |
| 48 | public static byte[] getLinkID(Long src_dpid, Long src_port_no, |
| 49 | Long dst_dpid, Long dst_port_no) { |
| 50 | return ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L') |
| 51 | .put(PortEvent.getPortID(src_dpid, src_port_no)) |
| 52 | .put(PortEvent.getPortID(dst_dpid, dst_port_no)).array(); |
| 53 | } |
| 54 | |
Pavlin Radoslavov | 45ec04b | 2014-02-14 23:29:33 -0800 | [diff] [blame] | 55 | public byte[] getID() { |
| 56 | return getLinkID(src.getDpid(), src.getNumber(), |
| 57 | dst.getDpid(), dst.getNumber()); |
| 58 | } |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 59 | } |