blob: df61e51b3dded863b8a0b01bd0e406961ee399d6 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.flowmanager;
2
3import java.util.ArrayList;
4import java.util.Iterator;
5import java.util.List;
6
7import net.onrc.onos.core.util.Dpid;
8
9/**
10 * Path representation for the flow manager.
11 */
12public class Path extends FlowLinks {
13 /**
14 * Default constructor to create an empty path.
15 */
16 public Path() {
17 super();
18 }
19
20 /**
21 * Gets a list of switch DPIDs of the path.
22 *
23 * @return a list of Dpid objects
24 */
25 public List<Dpid> getDpids() {
26 if (size() < 1) {
27 return null;
28 }
29
30 List<Dpid> dpids = new ArrayList<Dpid>(size() + 1);
31 dpids.add(getSrcDpid());
32 for (FlowLink link: this) {
33 dpids.add(link.getDstDpid());
34 }
35 return dpids;
36 }
37
38 /**
39 * Gets the DPID of the first switch.
40 *
41 * @return a Dpid object of the first switch.
42 */
43 public Dpid getSrcDpid() {
44 if (size() < 1) {
45 return null;
46 }
47 return get(0).getSrcDpid();
48 }
49
50 /**
51 * Gets the DPID of the last switch.
52 *
53 * @return a Dpid object of the last switch.
54 */
55 public Dpid getDstDpid() {
56 if (size() < 1) {
57 return null;
58 }
59 return get(size() - 1).getDstDpid();
60 }
61
62 /**
63 * Returns a string representation of the path.
64 *
65 * @return a string representation of the path.
66 */
67 @Override
68 public String toString() {
69 StringBuilder builder = new StringBuilder();
70 Iterator<FlowLink> i = this.iterator();
71 while (i.hasNext()) {
72 builder.append(i.next().toString());
73 if (i.hasNext()) {
74 builder.append(", ");
75 }
76 }
77 return builder.toString();
78 }
79}