HIGUCHI Yuta | 0813793 | 2013-06-17 14:11:50 -0700 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.core.internal; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 2 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.*; |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 4 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 5 | import java.util.ArrayList; |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 6 | import java.util.HashMap; |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 7 | import java.util.List; |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 8 | import java.util.Map; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 9 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 10 | import net.floodlightcontroller.routing.Link; |
Pankaj Berde | 38646d6 | 2013-06-21 11:34:04 -0700 | [diff] [blame] | 11 | import net.onrc.onos.graph.GraphDBConnection; |
| 12 | import net.onrc.onos.graph.GraphDBOperation; |
HIGUCHI Yuta | 2d01158 | 2013-06-15 01:47:11 -0700 | [diff] [blame] | 13 | import net.onrc.onos.ofcontroller.core.ILinkStorage; |
HIGUCHI Yuta | 2051490 | 2013-06-12 11:24:16 -0700 | [diff] [blame] | 14 | import net.onrc.onos.ofcontroller.core.INetMapStorage.DM_OPERATION; |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 15 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.IPortObject; |
| 16 | import net.onrc.onos.ofcontroller.core.INetMapTopologyObjects.ISwitchObject; |
| 17 | import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 18 | |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 19 | import org.easymock.*; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 22 | import org.junit.Ignore; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 23 | import org.junit.Test; |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 24 | import org.junit.runner.RunWith; |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 25 | import org.openflow.protocol.OFPhysicalPort; |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 26 | import org.openflow.util.HexString; |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 27 | import org.powermock.api.easymock.PowerMock; |
| 28 | import org.powermock.core.classloader.annotations.PrepareForTest; |
| 29 | import org.powermock.modules.junit4.PowerMockRunner; |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 32 | |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Unit test for {@link LinkStorageImpl}. |
| 35 | * @author Naoki Shiota |
| 36 | * |
| 37 | */ |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 38 | @RunWith(PowerMockRunner.class) |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 39 | @PrepareForTest({LinkStorageImpl.class, GraphDBConnection.class, GraphDBOperation.class}) |
Naoki Shiota | 991093a | 2013-12-10 14:47:18 -0800 | [diff] [blame] | 40 | @SuppressWarnings("serial") |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 41 | public class LinkStorageImplTest { |
Yuta HIGUCHI | 6ac8d18 | 2013-10-22 15:24:56 -0700 | [diff] [blame] | 42 | protected final static Logger log = LoggerFactory.getLogger(LinkStorageImplTest.class); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 43 | |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 44 | private static ILinkStorage linkStorage; |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 45 | |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 46 | // Mock GraphDBConnection (do nothing) |
| 47 | private static GraphDBConnection conn; |
| 48 | |
| 49 | // Mock GraphDBOperation (mocks port-related methods only) |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 50 | private static GraphDBOperation ope; |
| 51 | |
| 52 | // Uncommitted actions executed in LinkStorageImpl |
| 53 | private static ArrayList<LinkEvent> actions; |
| 54 | |
| 55 | // Dictionary of mock IPortObject to information of port |
| 56 | // -> Used to refer DPID from IPortObject |
| 57 | private static Map<IPortObject,PortInfo> mockToPortInfoMap; |
| 58 | |
| 59 | |
| 60 | // Links existing in virtual graph |
| 61 | private List<Link> links; |
| 62 | |
| 63 | //================ Utility classes for logging actions in LinkStorageImpl =========== |
| 64 | private enum LinkEventType { |
| 65 | ADD, DELETE |
| 66 | } |
| 67 | |
| 68 | private class LinkEvent { |
| 69 | private Long src_dpid = null; |
| 70 | private Long dst_dpid = null; |
| 71 | private Short src_port = null; |
| 72 | private Short dst_port = null; |
| 73 | |
| 74 | public LinkEventType type; |
| 75 | |
| 76 | public LinkEvent(Link link, LinkEventType type) { |
| 77 | this.src_dpid = link.getSrc(); |
| 78 | this.src_port = link.getSrcPort(); |
| 79 | this.dst_dpid = link.getDst(); |
| 80 | this.dst_port = link.getDstPort(); |
| 81 | |
| 82 | this.type = type; |
| 83 | } |
| 84 | |
| 85 | public Long getSrcDpid() { return src_dpid; } |
| 86 | public Short getSrcPort() { return src_port; } |
| 87 | public Long getDstDpid() { return dst_dpid; } |
| 88 | public Short getDstPort() { return dst_port; } |
| 89 | public LinkEventType getType() { return type; } |
| 90 | } |
| 91 | |
| 92 | private class PortInfo { |
| 93 | public Long dpid = null; |
| 94 | public Short port = null; |
| 95 | |
| 96 | public PortInfo(Long dpid, Short port) { this.dpid = dpid; this.port = port; } |
| 97 | } |
mininet | 37dc589 | 2013-06-04 10:58:44 -0700 | [diff] [blame] | 98 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Setup code called before each tests. |
| 101 | * Read test graph data and replace DB access by test graph data. |
| 102 | * @throws Exception |
| 103 | */ |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 104 | @Before |
Jonathan Hart | 627f10c | 2013-01-16 14:20:03 -0800 | [diff] [blame] | 105 | public void setUp() throws Exception{ |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 106 | // Create mock GraphDBConnection (replace Singleton object to mock one) |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 107 | PowerMock.mockStatic(GraphDBConnection.class); |
| 108 | PowerMock.suppress(PowerMock.constructor(GraphDBConnection.class)); |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 109 | conn = PowerMock.createMock(GraphDBConnection.class); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 110 | EasyMock.expect(GraphDBConnection.getInstance((String)EasyMock.anyObject())).andReturn(conn).anyTimes(); |
| 111 | PowerMock.replay(GraphDBConnection.class); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 112 | |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 113 | // Create mock GraphDBOperation |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 114 | ope = createMockGraphDBOperation(); |
| 115 | PowerMock.expectNew(GraphDBOperation.class, new Class<?>[] {GraphDBConnection.class}, EasyMock.anyObject(GraphDBConnection.class)).andReturn(ope).anyTimes(); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 116 | PowerMock.replay(GraphDBOperation.class); |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 117 | |
| 118 | actions = new ArrayList<LinkEvent>(); |
| 119 | mockToPortInfoMap = new HashMap<IPortObject,PortInfo>(); |
| 120 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 121 | linkStorage = new LinkStorageImpl(); |
yoshi | 2fd4c7e | 2013-11-22 15:47:55 -0800 | [diff] [blame] | 122 | linkStorage.init("dummyStore", "/dummy/path/to/conf"); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 123 | |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 124 | initLinks(); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 125 | } |
| 126 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 127 | /** |
| 128 | * Closing code called after each tests. |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 129 | * @throws Exception |
| 130 | */ |
Jonathan Hart | d1c5a1c | 2013-01-23 00:56:14 -0800 | [diff] [blame] | 131 | @After |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 132 | public void tearDown() throws Exception { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 133 | linkStorage.close(); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * Test if {@link LinkStorageImpl#addLink(Link)} can correctly creates a Link. |
| 139 | */ |
| 140 | @Test |
| 141 | public void testAddLink() { |
| 142 | Link linkToCreate = createFeasibleLink(); |
| 143 | Link linkToVerify = createFeasibleLink(); |
| 144 | |
| 145 | //Use the link storage API to add the link |
| 146 | linkStorage.addLink(linkToCreate); |
| 147 | doTestLinkExist(linkToVerify); |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly creates multiple Links. |
| 152 | */ |
| 153 | @Test |
| 154 | public void testAddLinks() { |
| 155 | List<Link> linksToCreate = createFeasibleLinks(); |
| 156 | List<Link> linksToVerify = createFeasibleLinks(); |
| 157 | |
| 158 | // Test creation of new links |
| 159 | linkStorage.addLinks(linksToCreate); |
| 160 | for(Link l : linksToVerify) { |
| 161 | doTestLinkExist(l); |
| 162 | } |
| 163 | } |
| 164 | |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 165 | // TODO: remove @Ignore after UPDATE method is implemented |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 166 | /** |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 167 | * Test if {@link LinkStorageImpl#updateLinkInfo(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 168 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 169 | @Ignore @Test |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 170 | public void testUpdate_Update() { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 171 | Link linkToUpdate= createExistingLink(); |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 172 | long currentTime = System.currentTimeMillis(); |
| 173 | LinkInfo infoToUpdate = createFeasibleLinkInfo(currentTime); |
| 174 | LinkInfo infoToVerify = createFeasibleLinkInfo(currentTime); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 175 | |
| 176 | linkStorage.update(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE); |
| 177 | |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 178 | doTestLinkHasStateOf(linkToUpdate, infoToVerify); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 181 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 182 | * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly creates a Link. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 183 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 184 | @Test |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 185 | public void testUpdate_Create() { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 186 | Link linkToCreate = createFeasibleLink(); |
| 187 | Link linkToVerify = createFeasibleLink(); |
| 188 | |
| 189 | //Use the link storage API to add the link |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 190 | linkStorage.update(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 191 | doTestLinkExist(linkToVerify); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 194 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 195 | * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)}can correctly inserts a Link. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 196 | */ |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 197 | @Test |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 198 | public void testUpdate_Insert(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 199 | Link linkToInsert = createFeasibleLink(); |
| 200 | Link linkToVerify = createFeasibleLink(); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 201 | |
| 202 | //Use the link storage API to add the link |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 203 | linkStorage.update(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 204 | doTestLinkExist(linkToVerify); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 207 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 208 | * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly deletes a Link. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 209 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 210 | @Test |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 211 | public void testUpdate_Delete(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 212 | Link linkToDelete = createExistingLink(); |
| 213 | Link linkToVerify = createExistingLink(); |
| 214 | |
| 215 | // Test deletion of existing link |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 216 | linkStorage.update(linkToDelete, null, DM_OPERATION.DELETE); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 217 | doTestLinkNotExist(linkToVerify); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 218 | } |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 221 | * Test if {@link LinkStorageImpl#getLinks(Long, short)} can correctly return Links connected to specific DPID and port. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 222 | */ |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 223 | @Test |
| 224 | public void testGetLinks_ByDpidPort(){ |
| 225 | Link linkToVerify = createExistingLink(); |
| 226 | Long dpid = linkToVerify.getSrc(); |
| 227 | short port = (short)linkToVerify.getSrcPort(); |
| 228 | |
| 229 | List<Link> list = linkStorage.getLinks(dpid, port); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 230 | |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 231 | assertEquals(1, list.size()); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 232 | |
| 233 | Link l = list.get(0); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 234 | assertEquals(l.getSrc(), linkToVerify.getSrc()); |
| 235 | assertEquals(l.getSrcPort(), linkToVerify.getSrcPort()); |
| 236 | assertEquals(l.getDst(), linkToVerify.getDst()); |
| 237 | assertEquals(l.getDstPort(), linkToVerify.getDstPort()); |
| 238 | |
| 239 | Link linkToVerifyNot = createFeasibleLink(); |
| 240 | |
| 241 | List<Link> list2 = linkStorage.getLinks(linkToVerifyNot.getSrc(), (short)linkToVerifyNot.getSrcPort()); |
| 242 | |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 243 | assertEquals(0, list2.size()); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 246 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 247 | * Test if {@link LinkStorageImpl#getLinks(String)} can correctly return Links connected to specific MAC address. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 248 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 249 | @Test |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 250 | public void testGetLinks_ByString() { |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 251 | Link linkToVeryfy = createExistingLink(); |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 252 | String dpid = HexString.toHexString(linkToVeryfy.getSrc()); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 253 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 254 | List<Link> links = linkStorage.getLinks(dpid); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 255 | assertTrue(links.contains(linkToVeryfy)); |
| 256 | |
| 257 | Link linkToVerifyNot = createFeasibleLink(); |
| 258 | assertFalse(links.contains(linkToVerifyNot)); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 259 | } |
Pavlin Radoslavov | 613eedc | 2013-11-02 16:08:25 -0700 | [diff] [blame] | 260 | |
| 261 | /** |
| 262 | * Test if {@link LinkStorageImpl#getReverseLinks(String)} can correctly return Links connected to specific MAC address. |
| 263 | */ |
| 264 | @Test |
| 265 | public void testGetReverseLinks_ByString() { |
| 266 | Link linkToVeryfy = createExistingLink(); |
| 267 | String dpid = HexString.toHexString(linkToVeryfy.getDst()); |
| 268 | |
| 269 | List<Link> links = linkStorage.getReverseLinks(dpid); |
| 270 | assertTrue(links.contains(linkToVeryfy)); |
| 271 | |
| 272 | Link linkToVerifyNot = createFeasibleLink(); |
| 273 | assertFalse(links.contains(linkToVerifyNot)); |
| 274 | } |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 275 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 276 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 277 | * Test if {@link LinkStorageImpl#deleteLink(Link)} can correctly delete a Link. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 278 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 279 | @Test |
| 280 | public void testDeleteLink() { |
| 281 | // Deletion of existing link |
| 282 | Link linkToDelete = createExistingLink(); |
| 283 | Link linkToVerify = createExistingLink(); |
| 284 | |
| 285 | linkStorage.deleteLink(linkToDelete); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 286 | doTestLinkNotExist(linkToVerify); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 289 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 290 | * Test if {@link LinkStorageImpl#deleteLinks(List)} can correctly delete Links. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 291 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 292 | @Test |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 293 | public void testDeleteLinks(){ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 294 | List<Link> linksToDelete = createExistingLinks(); |
| 295 | List<Link> linksToVerify = createExistingLinks(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 296 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 297 | linkStorage.deleteLinks(linksToDelete); |
| 298 | for(Link l : linksToVerify) { |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 299 | doTestLinkNotExist(l); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 302 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 303 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 304 | * Test if {@link LinkStorageImpl#getActiveLinks()} can correctly return active Links. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 305 | */ |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 306 | @Test |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 307 | public void testGetActiveLinks() { |
| 308 | Link existingLink = createExistingLink(); |
| 309 | Link notExistingLink = createFeasibleLink(); |
| 310 | |
| 311 | List<Link> links = linkStorage.getActiveLinks(); |
Jonathan Hart | c86a2ea | 2013-01-15 22:39:42 -0800 | [diff] [blame] | 312 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 313 | assertTrue(links.contains(existingLink)); |
| 314 | assertFalse(links.contains(notExistingLink)); |
| 315 | } |
| 316 | |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 317 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 318 | * Test if {@link LinkStorageImpl#deleteLinksOnPort(Long, short)} can delete Links. |
Naoki Shiota | 1b97286 | 2013-06-05 19:49:09 -0700 | [diff] [blame] | 319 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 320 | @Test |
| 321 | public void testDeleteLinksOnPort() { |
| 322 | Link linkToDelete = createExistingLink(); |
| 323 | Link linkToVerify = createExistingLink(); |
| 324 | |
| 325 | linkStorage.deleteLinksOnPort(linkToDelete.getSrc(), linkToDelete.getSrcPort()); |
| 326 | |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 327 | doTestLinkNotExist(linkToVerify); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 328 | } |
Naoki Shiota | b2d17e8 | 2013-10-18 18:08:16 -0700 | [diff] [blame] | 329 | |
| 330 | /** |
| 331 | * Test if {@link LinkStorageImpl#getLinkInfo(Link)} can delete Links. |
| 332 | */ |
| 333 | @Ignore @Test |
| 334 | public void testGetLinkInfo() { |
| 335 | fail("not yet implemented"); |
| 336 | } |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 337 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 338 | /** |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 339 | * Test if specific link exists |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 340 | * @param link |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 341 | */ |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 342 | private void doTestLinkExist(Link link) { |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 343 | int count = 0; |
| 344 | for(Link lt : links) { |
| 345 | if(lt.equals(link)) { |
| 346 | ++count; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | assertTrue(count == 1); |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 351 | } |
| 352 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 353 | /** |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 354 | * Test if specific link doesn't exist |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 355 | * @param link |
| 356 | */ |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 357 | private void doTestLinkNotExist(Link link) { |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 358 | assertFalse(links.contains(link)); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 359 | } |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 360 | |
| 361 | /** |
| 362 | * Test if titanGraph has specific Link with specific LinkInfo |
| 363 | * @param link |
| 364 | */ |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 365 | // TODO: Fix me |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 366 | private void doTestLinkHasStateOf(Link link, LinkInfo info) { |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 367 | } |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 368 | |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 369 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 370 | * Class defines a function called back when {@link IPortObject#removeLink(IPortObject)} is called. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 371 | * @author Naoki Shiota |
| 372 | * |
| 373 | */ |
| 374 | private class RemoveLinkCallback implements IAnswer<Object> { |
| 375 | private long dpid; |
| 376 | private short port; |
| 377 | public RemoveLinkCallback(long dpid, short port) { |
| 378 | this.dpid = dpid; this.port = port; |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | public Object answer() throws Throwable { |
| 383 | IPortObject dstPort = (IPortObject) EasyMock.getCurrentArguments()[0]; |
| 384 | PortInfo dst = mockToPortInfoMap.get(dstPort); |
| 385 | |
| 386 | Link linkToRemove = new Link(this.dpid,this.port,dst.dpid,dst.port); |
| 387 | actions.add(new LinkEvent(linkToRemove,LinkEventType.DELETE)); |
| 388 | |
| 389 | return null; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 394 | * Class defines a function called back when {@link IPortObject#setLinkPort(IPortObject)} is called. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 395 | * @author Naoki Shiota |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 396 | */ |
| 397 | private class SetLinkPortCallback implements IAnswer<Object> { |
| 398 | private long dpid; |
| 399 | private short port; |
| 400 | public SetLinkPortCallback(long dpid, short port) { |
| 401 | this.dpid = dpid; this.port = port; |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public Object answer() throws Throwable { |
| 406 | IPortObject dstPort = (IPortObject) EasyMock.getCurrentArguments()[0]; |
| 407 | PortInfo dst = mockToPortInfoMap.get(dstPort); |
| 408 | |
| 409 | Link linkToAdd = new Link(this.dpid,this.port,dst.dpid,dst.port); |
| 410 | actions.add(new LinkEvent(linkToAdd,LinkEventType.ADD)); |
| 411 | |
| 412 | return null; |
| 413 | } |
| 414 | |
| 415 | } |
| 416 | |
| 417 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 418 | * Class defines a function called back when {@link IPortObject#getSwitch()} is called. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 419 | * @author Naoki Shiota |
| 420 | * |
| 421 | */ |
| 422 | private class GetSwitchCallback implements IAnswer<ISwitchObject> { |
| 423 | private long dpid; |
| 424 | |
| 425 | public GetSwitchCallback(long dpid) { |
| 426 | this.dpid = dpid; |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public ISwitchObject answer() throws Throwable { |
| 431 | ISwitchObject sw = createMockSwitch(dpid); |
| 432 | return sw; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 437 | * Class defines a function called back when {@link IPortObject#getLinkedPorts()} is called. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 438 | * @author Naoki Shiota |
| 439 | * |
| 440 | */ |
| 441 | private class GetLinkedPortsCallback implements IAnswer< Iterable<IPortObject> > { |
| 442 | private long dpid; |
| 443 | private short port; |
| 444 | |
| 445 | public GetLinkedPortsCallback(long dpid, short port) { |
| 446 | this.dpid = dpid; |
| 447 | this.port = port; |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public Iterable<IPortObject> answer() throws Throwable { |
| 452 | List<IPortObject> ports = new ArrayList<IPortObject>(); |
| 453 | |
| 454 | for(Link lk : links) { |
| 455 | if(lk.getSrc() == dpid && lk.getSrcPort() == port) { |
| 456 | ports.add(createMockPort(lk.getDst(), lk.getDstPort())); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | return ports; |
| 461 | } |
| 462 | |
| 463 | } |
| 464 | |
| 465 | /** |
Pavlin Radoslavov | 613eedc | 2013-11-02 16:08:25 -0700 | [diff] [blame] | 466 | * Class defines a function called back when {@link IPortObject#getReverseLinkedPorts()} is called. |
| 467 | * @author Naoki Shiota |
| 468 | * |
| 469 | */ |
| 470 | private class GetReverseLinkedPortsCallback implements IAnswer< Iterable<IPortObject> > { |
| 471 | private long dpid; |
| 472 | private short port; |
| 473 | |
| 474 | public GetReverseLinkedPortsCallback(long dpid, short port) { |
| 475 | this.dpid = dpid; |
| 476 | this.port = port; |
| 477 | } |
| 478 | |
| 479 | @Override |
| 480 | public Iterable<IPortObject> answer() throws Throwable { |
| 481 | List<IPortObject> ports = new ArrayList<IPortObject>(); |
| 482 | |
| 483 | for(Link lk : links) { |
| 484 | if(lk.getDst() == dpid && lk.getDstPort() == port) { |
| 485 | ports.add(createMockPort(lk.getSrc(), lk.getSrcPort())); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | return ports; |
| 490 | } |
| 491 | |
| 492 | } |
| 493 | |
| 494 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 495 | * Class defines a function called back when {@link LinkStorageImplTest} is called. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 496 | * @author Naoki Shiota |
| 497 | * |
| 498 | */ |
| 499 | private class GetPortsCallback implements IAnswer< Iterable <IPortObject> > { |
| 500 | private long dpid; |
| 501 | |
| 502 | public GetPortsCallback(long dpid) { |
| 503 | this.dpid = dpid; |
| 504 | } |
| 505 | |
| 506 | @Override |
| 507 | public Iterable<IPortObject> answer() throws Throwable { |
| 508 | List<IPortObject> ports = new ArrayList<IPortObject>(); |
| 509 | |
| 510 | for(Short number : getPorts(dpid)) { |
| 511 | ports.add(createMockPort(dpid, number)); |
| 512 | } |
| 513 | |
| 514 | return ports; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | // ------------------------Creation of Mock----------------------------- |
| 519 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 520 | * Create a mock {@link GraphDBOperation} which hooks port-related methods. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 521 | * @return EasyMock-wrapped GraphDBOperation object. |
| 522 | */ |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 523 | private GraphDBOperation createMockGraphDBOperation() { |
| 524 | GraphDBOperation mockDBOpe = EasyMock.createNiceMock(GraphDBOperation.class); |
| 525 | |
| 526 | // Mock searchPort() method to create new mock IPortObject. |
| 527 | EasyMock.expect(mockDBOpe.searchPort((String)EasyMock.anyObject(), EasyMock.anyShort())). |
| 528 | andAnswer(new IAnswer<IPortObject>() { |
| 529 | @Override |
| 530 | public IPortObject answer() throws Throwable { |
| 531 | long dpid = HexString.toLong((String)EasyMock.getCurrentArguments()[0]); |
| 532 | short port = (Short) EasyMock.getCurrentArguments()[1]; |
| 533 | IPortObject ret = createMockPort(dpid,port); |
| 534 | |
| 535 | return ret; |
| 536 | } |
| 537 | }).anyTimes(); |
| 538 | |
| 539 | // Mock searchSwitch() method to create new mock ISwitchObject. |
| 540 | EasyMock.expect(mockDBOpe.searchSwitch((String)EasyMock.anyObject())). |
| 541 | andAnswer(new IAnswer<ISwitchObject>() { |
| 542 | @Override |
| 543 | public ISwitchObject answer() throws Throwable { |
| 544 | long dpid = HexString.toLong((String)EasyMock.getCurrentArguments()[0]); |
| 545 | ISwitchObject ret = createMockSwitch(dpid); |
| 546 | |
| 547 | return ret; |
| 548 | } |
| 549 | }).anyTimes(); |
| 550 | |
| 551 | // Mock getActiveSwitches() method to create list of mock ISwitchObject. |
| 552 | EasyMock.expect(mockDBOpe.getActiveSwitches()).andReturn(new ArrayList<ISwitchObject> () {{ |
| 553 | for(Long dpid : getDpids()) { |
| 554 | add(createMockSwitch(dpid)); |
| 555 | } |
| 556 | }}).anyTimes(); |
| 557 | |
| 558 | // Mock commit() method to commit change of link information |
| 559 | mockDBOpe.commit(); |
| 560 | EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() { |
| 561 | @Override |
| 562 | public Object answer() throws Throwable { |
| 563 | for(LinkEvent action : actions) { |
| 564 | if(action.getType().equals(LinkEventType.ADD)) { |
| 565 | Link linkToAdd = new Link( |
| 566 | action.getSrcDpid(), |
| 567 | action.getSrcPort(), |
| 568 | action.getDstDpid(), |
| 569 | action.getDstPort()); |
| 570 | links.add(linkToAdd); |
| 571 | } else if(action.getType().equals(LinkEventType.DELETE)) { |
| 572 | Link linkToRemove = new Link( |
| 573 | action.getSrcDpid(), |
| 574 | action.getSrcPort(), |
| 575 | action.getDstDpid(), |
| 576 | action.getDstPort()); |
| 577 | links.remove(linkToRemove); |
| 578 | } else { |
| 579 | log.error("mock commit(): unexpected action {}", new Object[]{action.getType()}); |
| 580 | } |
| 581 | } |
| 582 | actions.clear(); |
| 583 | return null; |
| 584 | } |
| 585 | }).atLeastOnce(); |
| 586 | |
| 587 | EasyMock.replay(mockDBOpe); |
| 588 | return mockDBOpe; |
| 589 | } |
| 590 | |
| 591 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 592 | * Create a mock {@link IPortObject} using given DPID and port number. |
| 593 | * {@link IPortObject} can't store DPID, so DPID is stored to mockToPortInfoMap for later use. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 594 | * Duplication is not checked. |
| 595 | * @param dpid DPID of a port |
| 596 | * @param number Port Number |
| 597 | * @return EasyMock-wrapped IPortObject |
| 598 | */ |
| 599 | private IPortObject createMockPort(long dpid, short number) { |
| 600 | IPortObject mockPort = EasyMock.createNiceMock(IPortObject.class); |
| 601 | |
| 602 | EasyMock.expect(mockPort.getNumber()).andReturn(number); |
| 603 | |
| 604 | // Mock removeLink() method |
| 605 | mockPort.removeLink((IPortObject) EasyMock.anyObject()); |
| 606 | EasyMock.expectLastCall().andAnswer(new RemoveLinkCallback(dpid, number)).anyTimes(); |
| 607 | |
| 608 | // Mock setLinkPort() method |
| 609 | mockPort.setLinkPort((IPortObject) EasyMock.anyObject()); |
| 610 | EasyMock.expectLastCall().andAnswer(new SetLinkPortCallback(dpid, number)).anyTimes(); |
| 611 | |
| 612 | // Mock getLinkPorts() method |
| 613 | EasyMock.expect(mockPort.getLinkedPorts()).andAnswer(new GetLinkedPortsCallback(dpid, number)).anyTimes(); |
Pavlin Radoslavov | 613eedc | 2013-11-02 16:08:25 -0700 | [diff] [blame] | 614 | |
| 615 | // Mock getReverseLinkPorts() method |
| 616 | EasyMock.expect(mockPort.getReverseLinkedPorts()).andAnswer(new GetReverseLinkedPortsCallback(dpid, number)).anyTimes(); |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 617 | |
| 618 | // Mock getSwitch() method |
| 619 | EasyMock.expect(mockPort.getSwitch()).andAnswer(new GetSwitchCallback(dpid)).anyTimes(); |
| 620 | |
| 621 | mockToPortInfoMap.put(mockPort, new PortInfo(dpid,number)); |
| 622 | EasyMock.replay(mockPort); |
| 623 | |
| 624 | return mockPort; |
| 625 | } |
| 626 | |
| 627 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 628 | * Create a mock {@link ISwitchObject} using given DPID number. |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 629 | * Duplication is not checked. |
| 630 | * @param dpid DPID of a switch |
| 631 | * @return EasyMock-wrapped ISwitchObject |
| 632 | */ |
| 633 | private ISwitchObject createMockSwitch(long dpid) { |
| 634 | ISwitchObject mockSw = EasyMock.createNiceMock(ISwitchObject.class); |
| 635 | |
| 636 | EasyMock.expect(mockSw.getPorts()).andAnswer(new GetPortsCallback(dpid)).anyTimes(); |
| 637 | EasyMock.expect(mockSw.getDPID()).andReturn(HexString.toHexString(dpid)).anyTimes(); |
| 638 | EasyMock.expect(mockSw.getState()).andReturn("ACTIVE").anyTimes(); |
| 639 | |
| 640 | EasyMock.replay(mockSw); |
| 641 | return mockSw; |
| 642 | } |
| 643 | |
| 644 | |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 645 | //----------------- Creation of test data ----------------------- |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 646 | // Assume a network shown below. |
| 647 | // |
| 648 | // [dpid1]--+--[port:1]----[port:1]--+--[dpid2] |
| 649 | // | | |
| 650 | // +--[port:2] [port:2]--+ |
| 651 | // | |
| 652 | // +--[port:3] [port:1]--+--[dpid3] |
| 653 | // | | |
| 654 | // +--[port:4]----[port:2]--+ |
| 655 | // |
| 656 | // dpid1 : 00:00:00:00:0a:01 |
| 657 | // dpid2 : 00:00:00:00:0a:02 |
| 658 | // dpid3 : 00:00:00:00:0a:03 |
| 659 | |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 660 | /** |
| 661 | * Initialize links member to represent test topology above. |
| 662 | */ |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 663 | private void initLinks() { |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 664 | links = new ArrayList<Link>(); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 665 | |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 666 | links.add(new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a02"), 1)); |
| 667 | links.add(new Link(Long.decode("0x0000000000000a01"), 4, Long.decode("0x0000000000000a03"), 2)); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 668 | } |
| 669 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 670 | /** |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 671 | * Returns list of port number attached to the switch specified by given DPID. |
| 672 | * @param dpid DPID of the switch |
| 673 | * @return List of port number |
| 674 | */ |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 675 | private List<Short> getPorts(long dpid) { |
| 676 | List<Short> ports; |
| 677 | |
| 678 | if(dpid == Long.decode("0x0000000000000a01")) { |
| 679 | ports = new ArrayList<Short>() {{ |
| 680 | add((short)1); |
| 681 | add((short)2); |
| 682 | add((short)3); |
| 683 | add((short)4); |
| 684 | }}; |
| 685 | } else if(dpid == Long.decode("0x0000000000000a02") || dpid == Long.decode("0x0000000000000a03")) { |
| 686 | ports = new ArrayList<Short>() {{ |
| 687 | add((short)1); |
| 688 | add((short)2); |
| 689 | }}; |
| 690 | } else { |
| 691 | ports = new ArrayList<Short>(); |
| 692 | } |
| 693 | |
| 694 | return ports; |
| 695 | } |
| 696 | |
| 697 | /** |
| 698 | * Returns list of DPIDs in test topology. |
| 699 | * @return List of DPIDs |
| 700 | */ |
Naoki Shiota | 5f9197a | 2013-06-20 17:36:29 -0700 | [diff] [blame] | 701 | private List<Long> getDpids() { |
| 702 | List<Long> dpids = new ArrayList<Long>() {{ |
| 703 | add(Long.decode("0x0000000000000a01")); |
| 704 | add(Long.decode("0x0000000000000a02")); |
| 705 | add(Long.decode("0x0000000000000a03")); |
| 706 | }}; |
| 707 | |
| 708 | return dpids; |
| 709 | } |
| 710 | |
| 711 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 712 | * Returns new {@link Link} object of an existing link |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 713 | * @return new Link object |
| 714 | */ |
| 715 | private Link createExistingLink() { |
| 716 | return new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a02"), 1); |
| 717 | } |
| 718 | |
| 719 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 720 | * Returns new {@link Link} object of a not-existing but feasible link |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 721 | * @return new Link object |
| 722 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 723 | private Link createFeasibleLink() { |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 724 | return new Link(Long.decode("0x0000000000000a01"), 3, Long.decode("0x0000000000000a03"), 1); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 725 | } |
| 726 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 727 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 728 | * Returns list of existing {@link Link} objects |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 729 | * @return ArrayList of new Link objects |
| 730 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 731 | private List<Link> createExistingLinks() { |
| 732 | List<Link> links = new ArrayList<Link>(); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 733 | links.add(new Link(Long.decode("0x0000000000000a01"), 1, Long.decode("0x0000000000000a02"), 1)); |
| 734 | links.add(new Link(Long.decode("0x0000000000000a01"), 4, Long.decode("0x0000000000000a03"), 2)); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 735 | return links; |
| 736 | } |
| 737 | |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 738 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 739 | * Returns list of {@link Link} objects that are all not-existing but feasible |
mininet | 9d203de | 2013-06-05 08:40:45 -0700 | [diff] [blame] | 740 | * @return ArrayList of new Link objects |
| 741 | */ |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 742 | private List<Link> createFeasibleLinks() { |
| 743 | List<Link> links = new ArrayList<Link>(); |
Naoki Shiota | c88d956 | 2013-06-18 15:21:56 -0700 | [diff] [blame] | 744 | links.add(new Link(Long.decode("0x0000000000000a01"), 2, Long.decode("0x0000000000000a02"), 2)); |
| 745 | links.add(new Link(Long.decode("0x0000000000000a01"), 3, Long.decode("0x0000000000000a03"), 1)); |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 746 | return links; |
| 747 | } |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 748 | |
| 749 | /** |
Naoki Shiota | a3b2dfa | 2013-06-27 13:52:24 -0700 | [diff] [blame] | 750 | * Returns new {@link LinkInfo} object with convenient values. |
Naoki Shiota | cae568a | 2013-06-05 17:53:41 -0700 | [diff] [blame] | 751 | * @return LinkInfo object |
| 752 | */ |
| 753 | private LinkInfo createFeasibleLinkInfo(long time) { |
| 754 | long time_first = time; |
| 755 | long time_last_lldp = time + 50; |
| 756 | long time_last_bddp = time + 100; |
| 757 | int state_src = OFPhysicalPort.OFPortState.OFPPS_STP_FORWARD.getValue(); |
| 758 | int state_dst = OFPhysicalPort.OFPortState.OFPPS_STP_LISTEN.getValue(); |
| 759 | |
| 760 | return new LinkInfo(time_first, |
| 761 | time_last_lldp, |
| 762 | time_last_bddp, |
| 763 | state_src, |
| 764 | state_dst); |
| 765 | } |
mininet | 403d589 | 2013-06-05 03:48:17 -0700 | [diff] [blame] | 766 | //--------------------------------------------------------------- |
Jonathan Hart | b7e3d2c | 2013-01-15 18:45:19 -0800 | [diff] [blame] | 767 | } |