blob: ddbdbe728e052c1438a063dae88e0002f2facaf9 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Toshio Koideebdbb622014-02-12 20:28:38 -08002
Jonathan Hart472062d2014-04-03 10:56:48 -07003import net.onrc.onos.core.topology.Link;
4import net.onrc.onos.core.topology.LinkImpl;
Jonathan Hart472062d2014-04-03 10:56:48 -07005import net.onrc.onos.core.topology.Switch;
6import net.onrc.onos.core.topology.SwitchImpl;
Jonathan Harte37e4e22014-05-13 19:12:02 -07007import net.onrc.onos.core.topology.TopologyImpl;
Toshio Koideebdbb622014-02-12 20:28:38 -08008
Toshio Koide066506e2014-02-20 19:52:09 -08009/**
Jonathan Harte37e4e22014-05-13 19:12:02 -070010 * A mock class of Topology.
Toshio Koidefe1d5d92014-02-26 20:09:48 -080011 * This class should be used only by test codes.
Toshio Koide066506e2014-02-20 19:52:09 -080012 */
Jonathan Harte37e4e22014-05-13 19:12:02 -070013public class MockTopology extends TopologyImpl {
14 // TODO this class doesn't seem like it should extend TopologyImpl. It
15 // isn't a Topology, it's more of a TopologyBuilder - methods to
16 // create an populate a fake topology that's not based on discovery
Jonathan Hart25bd53e2014-04-30 23:44:09 -070017 // data from the driver modules.
Jonathan Harte37e4e22014-05-13 19:12:02 -070018 // We may well need a MockTopology, but that's not what this class is
Jonathan Hart25bd53e2014-04-30 23:44:09 -070019 // doing.
20
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070021 public static final Long LOCAL_PORT = 0xFFFEL;
Ray Milkey269ffb92014-04-03 14:43:30 -070022 public SwitchImpl sw1, sw2, sw3, sw4;
Toshio Koidefe1d5d92014-02-26 20:09:48 -080023
Ray Milkey269ffb92014-04-03 14:43:30 -070024 public Switch addSwitch(Long switchId) {
25 SwitchImpl sw = new SwitchImpl(this, switchId);
26 this.putSwitch(sw);
27 return sw;
28 }
Toshio Koideebdbb622014-02-12 20:28:38 -080029
Ray Milkey269ffb92014-04-03 14:43:30 -070030 public Link[] addBidirectionalLinks(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
31 Link[] links = new Link[2];
Jonathan Hart25bd53e2014-04-30 23:44:09 -070032 links[0] = new LinkImpl(this, getPort(srcDpid, srcPortNo), getPort(dstDpid, dstPortNo));
33 links[1] = new LinkImpl(this, getPort(dstDpid, dstPortNo), getPort(srcDpid, srcPortNo));
34
35 putLink(links[0]);
36 putLink(links[1]);
Toshio Koide066506e2014-02-20 19:52:09 -080037
Ray Milkey269ffb92014-04-03 14:43:30 -070038 return links;
39 }
Toshio Koideebdbb622014-02-12 20:28:38 -080040
Ray Milkey269ffb92014-04-03 14:43:30 -070041 /**
42 * create sample topology of 4 switches and 5 bidirectional links.
43 * <pre>
44 * [1] --- [2]
45 * | / |
46 * | / |
47 * [4] --- [3]
48 * </pre>
49 */
50 public void createSampleTopology1() {
51 sw1 = (SwitchImpl) addSwitch(1L);
52 sw1.addPort(LOCAL_PORT);
53 sw2 = (SwitchImpl) addSwitch(2L);
54 sw2.addPort(LOCAL_PORT);
55 sw3 = (SwitchImpl) addSwitch(3L);
56 sw3.addPort(LOCAL_PORT);
57 sw4 = (SwitchImpl) addSwitch(4L);
58 sw4.addPort(LOCAL_PORT);
Toshio Koideebdbb622014-02-12 20:28:38 -080059
Ray Milkey269ffb92014-04-03 14:43:30 -070060 sw1.addPort(12L); // sw1 -> sw2
61 sw1.addPort(14L); // sw1 -> sw4
62 sw2.addPort(21L); // sw2 -> sw1
63 sw2.addPort(23L); // sw2 -> sw3
64 sw2.addPort(24L); // sw2 -> sw4
65 sw3.addPort(32L); // sw3 -> sw2
66 sw3.addPort(34L); // sw3 -> sw4
67 sw4.addPort(41L); // sw4 -> sw1
68 sw4.addPort(42L); // sw4 -> sw2
69 sw4.addPort(43L); // sw4 -> sw3
Toshio Koideebdbb622014-02-12 20:28:38 -080070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 addBidirectionalLinks(1L, 12L, 2L, 21L);
72 addBidirectionalLinks(2L, 23L, 3L, 32L);
73 addBidirectionalLinks(3L, 34L, 4L, 43L);
74 addBidirectionalLinks(4L, 41L, 1L, 14L);
75 addBidirectionalLinks(2L, 24L, 4L, 42L);
Toshio Koide0c9106d2014-02-19 15:26:38 -080076
Ray Milkey269ffb92014-04-03 14:43:30 -070077 // set capacity of all links to 1000Mbps
78 for (Link link : getLinks()) {
79 ((LinkImpl) link).setCapacity(1000.0);
80 }
81 }
82
83 public void removeLink(Long srcDpid, Long srcPortNo, Long dstDpid, Long dstPortNo) {
Jonathan Hart25bd53e2014-04-30 23:44:09 -070084 removeLink(getLink(srcDpid, srcPortNo, dstDpid, dstPortNo));
Ray Milkey269ffb92014-04-03 14:43:30 -070085 }
Toshio Koideebdbb622014-02-12 20:28:38 -080086}