Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.xran.impl; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.xran.asn1lib.api.CRNTI; |
| 23 | import org.onosproject.xran.asn1lib.api.ECGI; |
| 24 | import org.onosproject.xran.asn1lib.api.EUTRANCellIdentifier; |
| 25 | import org.onosproject.xran.asn1lib.api.PLMNIdentity; |
| 26 | import org.onosproject.xran.asn1lib.util.HexConverter; |
| 27 | import org.onosproject.xran.impl.entities.RnibCell; |
| 28 | import org.onosproject.xran.impl.entities.RnibLink; |
| 29 | import org.onosproject.xran.impl.entities.RnibUe; |
| 30 | |
| 31 | import javax.xml.bind.DatatypeConverter; |
| 32 | import java.util.List; |
| 33 | import java.util.function.Supplier; |
| 34 | |
| 35 | import static org.junit.Assert.assertEquals; |
| 36 | |
| 37 | public class DefaultXranStoreTest { |
| 38 | private static final CRNTI CRNTI0 = new CRNTI(new byte[]{(byte) 0xFF, (byte) 0xFF}, 16); |
| 39 | private static final CRNTI CRNTI1 = new CRNTI(new byte[]{(byte) 0xFA, (byte) 0xAF}, 16); |
| 40 | |
| 41 | private static final RnibUe UE0 = new RnibUe(); |
| 42 | private static final RnibUe UE1 = new RnibUe(); |
| 43 | |
| 44 | private static final RnibCell CELL0 = new RnibCell(); |
| 45 | private static final RnibCell CELL1 = new RnibCell(); |
| 46 | private static final String ECI0 = "00000010"; |
| 47 | private static final String ECI1 = "00000020"; |
| 48 | private static final long UEID0 = 0L; |
| 49 | private static final long UEID1 = 1L; |
| 50 | |
| 51 | private static DefaultXranStore store = new DefaultXranStore(); |
| 52 | |
| 53 | private static RnibLink primaryLink0; |
| 54 | private static RnibLink primaryLink1; |
| 55 | private static RnibLink nonServingLink0; |
| 56 | private static RnibLink nonServingLink1; |
| 57 | |
| 58 | private Supplier exception = () -> { |
| 59 | throw new IllegalArgumentException("item not found"); |
| 60 | }; |
| 61 | |
| 62 | @Before |
| 63 | public void setUp() throws Exception { |
| 64 | CELL0.setEcgi(hexToEcgi("000001", ECI0)); |
| 65 | CELL1.setEcgi(hexToEcgi("000002", ECI1)); |
| 66 | |
| 67 | UE0.setCrnti(CRNTI0); |
| 68 | UE0.setId(UEID0); |
| 69 | |
| 70 | UE1.setCrnti(CRNTI1); |
| 71 | UE1.setId(UEID1); |
| 72 | |
| 73 | store.storeCell(CELL0); |
| 74 | store.storeCell(CELL1); |
| 75 | |
| 76 | store.storeUe(CELL0, UE0); |
| 77 | store.storeUe(CELL1, UE1); |
| 78 | |
| 79 | store.putPrimaryLink(CELL0, UE0); |
| 80 | store.putPrimaryLink(CELL1, UE1); |
| 81 | |
| 82 | store.putNonServingLink(CELL0, UEID1); |
| 83 | store.putNonServingLink(CELL1, UEID0); |
| 84 | |
| 85 | primaryLink0 = store.getLink(CELL0.getEcgi(), UEID0).orElseThrow(exception); |
| 86 | primaryLink1 = store.getLink(CELL1.getEcgi(), UEID1).orElseThrow(exception); |
| 87 | |
| 88 | nonServingLink0 = store.getLink(CELL0.getEcgi(), UEID1).orElseThrow(exception); |
| 89 | nonServingLink1 = store.getLink(CELL1.getEcgi(), UEID0).orElseThrow(exception); |
| 90 | } |
| 91 | |
| 92 | @After |
| 93 | public void tearDown() throws Exception { |
| 94 | assertEquals("wrong remove", true, store.removeCell(CELL0.getEcgi())); |
| 95 | assertEquals("wrong remove", true, store.removeCell(CELL1.getEcgi())); |
| 96 | |
| 97 | assertEquals("wrong remove", true, store.removeUe(UEID0)); |
| 98 | assertEquals("wrong remove", true, store.removeUe(UEID1)); |
| 99 | |
| 100 | assertEquals("wrong remove", true, store.removeLink(primaryLink0.getLinkId())); |
| 101 | assertEquals("wrong remove", true, store.removeLink(primaryLink1.getLinkId())); |
| 102 | |
| 103 | assertEquals("wrong remove", true, store.removeLink(nonServingLink0.getLinkId())); |
| 104 | assertEquals("wrong remove", true, store.removeLink(nonServingLink1.getLinkId())); |
| 105 | |
| 106 | assertEquals("wrong len", 0, store.getCellNodes().size()); |
| 107 | assertEquals("wrong len", 0, store.getUeNodes().size()); |
| 108 | assertEquals("wrong len", 0, store.getNodes().size()); |
| 109 | assertEquals("wrong len", 0, store.getLinks().size()); |
| 110 | } |
| 111 | |
| 112 | private ECGI hexToEcgi(String plmnId, String eci) throws Exception { |
| 113 | byte[] bytes = HexConverter.fromShortHexString(plmnId); |
| 114 | byte[] bytearray = DatatypeConverter.parseHexBinary(eci); |
| 115 | |
| 116 | PLMNIdentity plmnIdentity = new PLMNIdentity(bytes); |
| 117 | EUTRANCellIdentifier eutranCellIdentifier = new EUTRANCellIdentifier(bytearray, 28); |
| 118 | |
| 119 | ECGI ecgi = new ECGI(); |
| 120 | ecgi.setEUTRANcellIdentifier(eutranCellIdentifier); |
| 121 | ecgi.setPLMNIdentity(plmnIdentity); |
| 122 | |
| 123 | return ecgi; |
| 124 | } |
| 125 | |
| 126 | @Test |
| 127 | public void getPrimaryLink() throws Exception { |
| 128 | assertEquals("wrong cell", CELL0, store.getPrimaryCell(UE0).orElseThrow(exception)); |
| 129 | assertEquals("wrong cell", CELL1, store.getPrimaryCell(UE1).orElseThrow(exception)); |
| 130 | } |
| 131 | |
| 132 | @Test |
| 133 | public void mapSize() throws Exception { |
| 134 | assertEquals("wrong len", 2, store.getCellNodes().size()); |
| 135 | assertEquals("wrong len", 2, store.getUeNodes().size()); |
| 136 | assertEquals("wrong len", 4, store.getNodes().size()); |
| 137 | assertEquals("wrong len", 4, store.getLinks().size()); |
| 138 | } |
| 139 | |
| 140 | @Test |
| 141 | public void getUe() throws Exception { |
| 142 | // GET FROM ID |
| 143 | assertEquals("wrong ue", UE0, store.getUe(UEID0).orElseThrow(exception)); |
| 144 | assertEquals("wrong ue", UE1, store.getUe(UEID1).orElseThrow(exception)); |
| 145 | |
| 146 | // GET FROM ECGI-CRNTI |
| 147 | assertEquals("wrong ue", UE0, store.getUe(CELL0.getEcgi(), CRNTI0).orElseThrow(exception)); |
| 148 | assertEquals("wrong ue", UE1, store.getUe(CELL1.getEcgi(), CRNTI1).orElseThrow(exception)); |
| 149 | |
| 150 | // GET FROM CRNTI |
| 151 | assertEquals("wrong crnti", CRNTI0, store.getCrnti(UEID0).orElseThrow(exception)); |
| 152 | assertEquals("wrong crnti", CRNTI1, store.getCrnti(UEID1).orElseThrow(exception)); |
| 153 | } |
| 154 | |
| 155 | @Test |
| 156 | public void getLink() throws Exception { |
| 157 | // GET FROM ID |
| 158 | assertEquals("wrong link", primaryLink0, store.getLink(CELL0.getEcgi(), UEID0).orElseThrow(exception)); |
| 159 | assertEquals("wrong link", primaryLink1, store.getLink(CELL1.getEcgi(), UEID1).orElseThrow(exception)); |
| 160 | assertEquals("wrong link", nonServingLink0, store.getLink(CELL0.getEcgi(), UEID1).orElseThrow(exception)); |
| 161 | assertEquals("wrong link", nonServingLink1, store.getLink(CELL1.getEcgi(), UEID0).orElseThrow(exception)); |
| 162 | |
| 163 | // GET FROM CRNTI |
| 164 | assertEquals("wrong link", primaryLink0, store.getLink(CELL0.getEcgi(), CRNTI0).orElseThrow(exception)); |
| 165 | assertEquals("wrong link", primaryLink1, store.getLink(CELL1.getEcgi(), CRNTI1).orElseThrow(exception)); |
| 166 | // GET FROM ECIHEX |
| 167 | assertEquals("wrong link", primaryLink0, store.getLink(ECI0, UEID0).orElseThrow(exception)); |
| 168 | assertEquals("wrong link", primaryLink1, store.getLink(ECI1, UEID1).orElseThrow(exception)); |
| 169 | assertEquals("wrong link", nonServingLink0, store.getLink(ECI0, UEID1).orElseThrow(exception)); |
| 170 | assertEquals("wrong link", nonServingLink1, store.getLink(ECI1, UEID0).orElseThrow(exception)); |
| 171 | |
| 172 | // LINKS SIZE |
| 173 | assertEquals("wrong link", 2, store.getLinks(CELL0.getEcgi()).size()); |
| 174 | assertEquals("wrong link", 2, store.getLinks(ECI0).size()); |
| 175 | assertEquals("wrong link", 2, store.getLinks(UEID0).size()); |
| 176 | assertEquals("wrong link", 2, store.getLinks(CELL1.getEcgi()).size()); |
| 177 | assertEquals("wrong link", 2, store.getLinks(ECI1).size()); |
| 178 | assertEquals("wrong link", 2, store.getLinks(UEID1).size()); |
| 179 | } |
| 180 | |
| 181 | @Test |
| 182 | public void getNodes() throws Exception { |
| 183 | List<RnibCell> cellNodes = store.getCellNodes(); |
| 184 | |
| 185 | assertEquals("wrong nodes", true, cellNodes.contains(CELL0)); |
| 186 | assertEquals("wrong nodes", true, cellNodes.contains(CELL1)); |
| 187 | |
| 188 | List<RnibUe> ueNodes = store.getUeNodes(); |
| 189 | |
| 190 | assertEquals("wrong nodes", true, ueNodes.contains(UE0)); |
| 191 | assertEquals("wrong nodes", true, ueNodes.contains(UE1)); |
| 192 | } |
| 193 | |
| 194 | @Test |
| 195 | public void crntiMap() throws Exception { |
| 196 | store.getCrnti().forEach( |
| 197 | (ecgiCrntiPair, aLong) -> assertEquals("wrong primary", |
| 198 | store.getCell(ecgiCrntiPair.getKey()).get(), |
| 199 | store.getPrimaryCell(store.getUe(aLong).orElseThrow(exception)).get() |
| 200 | ) |
| 201 | ); |
| 202 | } |
| 203 | } |