blob: 888779a7a85950adbe1af1c0644de20bb575134b [file] [log] [blame]
TeruU5d2c9392014-06-09 20:02:02 -07001package net.onrc.onos.core.topology;
2
3import net.floodlightcontroller.util.MACAddress;
4
5/**
6 * A mock class of Topology.
7 * This class should be used only by test codes.
8 */
9public class MockTopology extends TopologyImpl {
10 // TODO this class doesn't seem like it should extend TopologyImpl. It
11 // isn't a Topology, it's more of a TopologyBuilder - methods to
12 // create an populate a fake topology that's not based on discovery
13 // data from the driver modules.
14 // We may well need a MockTopology, but that's not what this class is
15 // doing.
16
17 public static final Long LOCAL_PORT = 0xFFFEL;
18 public SwitchImpl sw1, sw2, sw3, sw4;
19
20 public Switch addSwitch(Long switchId) {
21 SwitchImpl sw = new SwitchImpl(this, switchId);
22 this.putSwitch(sw);
23 return sw;
24 }
25
26 public Link[] addBidirectionalLinks(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
27 Link[] links = new Link[2];
28 links[0] = new LinkImpl(this, getPort(srcDpid, srcPortNo), getPort(dstDpid, dstPortNo));
29 links[1] = new LinkImpl(this, getPort(dstDpid, dstPortNo), getPort(srcDpid, srcPortNo));
30
31 putLink(links[0]);
32 putLink(links[1]);
33
34 return links;
35 }
36
37 /**
38 * create sample topology of 4 switches and 5 bidirectional links.
39 * <pre>
40 * [1] --- [2]
41 * | / |
42 * | / |
43 * [4] --- [3]
44 * </pre>
45 */
46 public void createSampleTopology1() {
47 sw1 = (SwitchImpl) addSwitch(1L);
48 sw1.addPort(LOCAL_PORT);
49 sw2 = (SwitchImpl) addSwitch(2L);
50 sw2.addPort(LOCAL_PORT);
51 sw3 = (SwitchImpl) addSwitch(3L);
52 sw3.addPort(LOCAL_PORT);
53 sw4 = (SwitchImpl) addSwitch(4L);
54 sw4.addPort(LOCAL_PORT);
55
56 sw1.addPort(12L); // sw1 -> sw2
57 sw1.addPort(14L); // sw1 -> sw4
58 sw2.addPort(21L); // sw2 -> sw1
59 sw2.addPort(23L); // sw2 -> sw3
60 sw2.addPort(24L); // sw2 -> sw4
61 sw3.addPort(32L); // sw3 -> sw2
62 sw3.addPort(34L); // sw3 -> sw4
63 sw4.addPort(41L); // sw4 -> sw1
64 sw4.addPort(42L); // sw4 -> sw2
65 sw4.addPort(43L); // sw4 -> sw3
66
67 addBidirectionalLinks(1L, 12L, 2L, 21L);
68 addBidirectionalLinks(2L, 23L, 3L, 32L);
69 addBidirectionalLinks(3L, 34L, 4L, 43L);
70 addBidirectionalLinks(4L, 41L, 1L, 14L);
71 addBidirectionalLinks(2L, 24L, 4L, 42L);
72
73 // set capacity of all links to 1000Mbps
74 for (Link link : getLinks()) {
75 ((LinkImpl) link).setCapacity(1000.0);
76 }
77 }
78
79 /**
80 * create sample topology of 4 switches and 5 bidirectional links.
81 * <pre>
82 *
83 *
84 * [H1]-[1] --- [2]
85 * | / |
86 * | / |
87 * [4] --- [3]-[H3]
88 * </pre>
89 */
90 public void createSampleTopology2() {
91 sw1 = (SwitchImpl) addSwitch(1L);
92 sw1.addPort(LOCAL_PORT);
93 sw2 = (SwitchImpl) addSwitch(2L);
94 sw2.addPort(LOCAL_PORT);
95 sw3 = (SwitchImpl) addSwitch(3L);
96 sw3.addPort(LOCAL_PORT);
97 sw4 = (SwitchImpl) addSwitch(4L);
98 sw4.addPort(LOCAL_PORT);
99
100 Port port12 = sw1.addPort(12L); // sw1 -> sw2
101 Port port14 = sw1.addPort(14L); // sw1 -> sw4
102 Port port15 = sw1.addPort(15L); // sw1 -> h1
103 Port port21 = sw2.addPort(21L); // sw2 -> sw1
104 Port port23 = sw2.addPort(23L); // sw2 -> sw3
105 Port port24 = sw2.addPort(24L); // sw2 -> sw4
106 Port port32 = sw3.addPort(32L); // sw3 -> sw2
107 Port port34 = sw3.addPort(34L); // sw3 -> sw4
108 Port port35 = sw3.addPort(35L); // sw3 -> h3
109 Port port41 = sw4.addPort(41L); // sw4 -> sw1
110 Port port42 = sw4.addPort(42L); // sw4 -> sw2
111 Port port43 = sw4.addPort(43L); // sw4 -> sw3
112
113 MACAddress mac1 = MACAddress.valueOf("00:44:33:22:11:00");
114 DeviceImpl dev1 = new DeviceImpl(this, mac1);
115 dev1.addAttachmentPoint(port15);
116 dev1.setLastSeenTime(1L);
117 this.putDevice(dev1);
118
119 MACAddress mac3 = MACAddress.valueOf("00:11:22:33:44:55");
120 DeviceImpl dev3 = new DeviceImpl(this, mac3);
121 dev3.addAttachmentPoint(port35);
122 dev3.setLastSeenTime(1L);
123 this.putDevice(dev3);
124
125 addBidirectionalLinks(1L, 12L, 2L, 21L);
126 addBidirectionalLinks(2L, 23L, 3L, 32L);
127 addBidirectionalLinks(3L, 34L, 4L, 43L);
128 addBidirectionalLinks(4L, 41L, 1L, 14L);
129 addBidirectionalLinks(2L, 24L, 4L, 42L);
130
131 // set capacity of all links to 1000Mbps
132 for (Link link : getLinks()) {
133 ((LinkImpl) link).setCapacity(1000.0);
134 }
135 }
136
137 public void removeLink(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
138 removeLink(getLink(srcDpid, srcPortNo, dstDpid, dstPortNo));
139 }
140}