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 | |
| 17 | public LinkEvent(Long src_dpid, Long src_port_no, Long dst_dpid, |
| 18 | Long dst_port_no) { |
| 19 | |
| 20 | src = new SwitchPort(src_dpid, src_port_no); |
| 21 | dst = new SwitchPort(dst_dpid, dst_port_no); |
| 22 | |
| 23 | } |
| 24 | |
| 25 | public SwitchPort getSrc() { |
| 26 | return src; |
| 27 | } |
| 28 | |
| 29 | public SwitchPort getDst() { |
| 30 | return dst; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public String toString() { |
| 35 | return "[LinkEvent " + src + "->" + dst + "]"; |
| 36 | } |
| 37 | |
Yuta HIGUCHI | b510728 | 2014-02-14 17:18:24 -0800 | [diff] [blame^] | 38 | public static final int LINKID_BYTES = 2 + PortEvent.PORTID_BYTES * 2; |
| 39 | |
| 40 | public static byte[] getLinkID(Long src_dpid, Long src_port_no, |
| 41 | Long dst_dpid, Long dst_port_no) { |
| 42 | return ByteBuffer.allocate(LinkEvent.LINKID_BYTES).putChar('L') |
| 43 | .put(PortEvent.getPortID(src_dpid, src_port_no)) |
| 44 | .put(PortEvent.getPortID(dst_dpid, dst_port_no)).array(); |
| 45 | } |
| 46 | |
Yuta HIGUCHI | 54ab8cd | 2014-02-11 09:43:34 -0800 | [diff] [blame] | 47 | } |