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