Re-enable tests on mappingservice.implementation
[lispflowmapping.git] / mappingservice / implementation / src / test / java / org / opendaylight / lispflowmapping / implementation / authentication / LispAuthenticationTest.java
index 204c1442119a388c8c6b656a98d84d3d106dc235..f61cd668efb3f20522cfa3cbbe35421febdbac07 100644 (file)
@@ -1,28 +1,38 @@
+/*
+ * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.lispflowmapping.implementation.authentication;
 
-import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
 
 import java.util.ArrayList;
 
 import junitx.framework.ArrayAssert;
 
-import org.junit.Ignore;
 import org.junit.Test;
-import org.opendaylight.lispflowmapping.implementation.serializer.MapRegisterSerializer;
-import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
+import org.opendaylight.lispflowmapping.lisp.util.LispAddressUtil;
+import org.opendaylight.lispflowmapping.lisp.serializer.MapRegisterSerializer;
 import org.opendaylight.lispflowmapping.tools.junit.BaseTestCase;
-import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.MapRegister;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecordBuilder;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.Ipv4Builder;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecord;
-import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapnotifymessage.MapNotifyBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.mapping.authkey.container.MappingAuthkeyBuilder;
 
 public class LispAuthenticationTest extends BaseTestCase {
+    private static final String PASSWORD = "password";
+    private static final String WRONG_PASSWORD = "wrongPassword";
+
+    private static final Eid EID = LispAddressUtil.asIpv4PrefixEid("153.16.254.1/32");
 
     @Test
     public void validate_WrongAuthentication() throws Exception {
@@ -37,13 +47,13 @@ public class LispAuthenticationTest extends BaseTestCase {
         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
         //
-        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
-                + "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 " //
-                + "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 00 00 " //
-                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
+                + "00 00 00 00 00 00 00 01 00 14 e8 f5 0b c5 c5 f2 "
+                + "b0 21 27 a8 21 41 04 f3 46 5a 5a 5b 5c 5d 00 00 "
+                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
-        assertFalse(LispAuthenticationUtil.validate(mapRegister, "password"));
+        assertFalse(validate(mapRegister, EID, 1, PASSWORD));
     }
 
     @Test
@@ -59,13 +69,13 @@ public class LispAuthenticationTest extends BaseTestCase {
         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
         //
-        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
-                + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 " //
-                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
+        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
+                + "00 00 00 00 00 00 00 01 00 14 2c 61 b9 c9 9a 20 ba d8 f5 40 d3 55 6f 5f 6e 5a b2 0a bf b5 00 00 "
+                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
 
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
-        assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+        assertTrue(validate(mapRegister, EID, 1, PASSWORD));
+        assertFalse(validate(mapRegister, EID, 1, WRONG_PASSWORD));
     }
 
     @Test
@@ -85,13 +95,16 @@ public class LispAuthenticationTest extends BaseTestCase {
         MapRegister mapRegister = MapRegisterSerializer
                 .getInstance()
                 .deserialize(
-                        hexToByteBuffer("38 00 01 01 FF BB " //
-                                + "00 00 00 00 00 00 00 02 00 20 70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d 68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 00 00 " //
-                                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                                + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
-        assertFalse(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+                        hexToByteBuffer("38 00 01 01 FF BB "
+                                + "00 00 00 00 00 00 00 02 00 20 "
+                                + "70 30 d4 c6 10 44 0d 83 be 4d bf fd a9 8c 57 6d "
+                                + "68 a5 bf 32 11 c9 7b 58 c4 b9 9f 06 11 23 b9 38 "
+                                + "00 00 "
+                                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
+
+        assertTrue(validate(mapRegister, EID, 2, PASSWORD));
+        assertFalse(validate(mapRegister, EID, 2, WRONG_PASSWORD));
     }
 
     @Test
@@ -106,14 +119,14 @@ public class LispAuthenticationTest extends BaseTestCase {
         // Local RLOC: 192.168.136.10 (RLOC=0xC0A8880A), Reachable,
         // Priority/Weight: 1/100, Multicast Priority/Weight: 255/0
         //
-        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB " //
-                + "00 00 00 00 00 00 00 00 00 00 " //
-                + "00 00 " //
-                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 " //
-                + "ff 00 00 05 00 01 c0 a8 88 0a"));
-
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "password"));
-        assertTrue(LispAuthenticationUtil.validate(mapRegister, "wrongPassword"));
+        MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(hexToByteBuffer("38 00 01 01 FF BB "
+                + "00 00 00 00 00 00 00 00 00 00 "
+                + "00 00 "
+                + "00 0a 01 20 10 00 00 00 00 01 99 10 fe 01 01 64 "
+                + "ff 00 00 05 00 01 c0 a8 88 0a"), null);
+
+        assertTrue(validate(mapRegister, EID, 0, PASSWORD));
+        assertTrue(validate(mapRegister, EID, 0, WRONG_PASSWORD));
     }
 
     // @Test
@@ -162,17 +175,20 @@ public class LispAuthenticationTest extends BaseTestCase {
     public void authenticate__MapNotifyNoAuthenticationData() throws Exception {
         MapNotifyBuilder mapNotifyBuilder = new MapNotifyBuilder();
         mapNotifyBuilder.setKeyId((short) 0x0000);
-        mapNotifyBuilder.setEidToLocatorRecord(new ArrayList<EidToLocatorRecord>());
-        EidToLocatorRecordBuilder etlrBuilder = new EidToLocatorRecordBuilder();
+        mapNotifyBuilder.setMappingRecordItem(new ArrayList<MappingRecordItem>());
+        MappingRecordBuilder etlrBuilder = new MappingRecordBuilder();
         etlrBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
-        etlrBuilder.setLispAddressContainer(LispAFIConvertor.toContainer(asIPAfiAddress("1.1.1.1")));
+        etlrBuilder.setEid(LispAddressUtil.asIpv4PrefixEid("1.1.1.1/32"));
         etlrBuilder.setRecordTtl(55);
-        mapNotifyBuilder.getEidToLocatorRecord().add(etlrBuilder.build());
-        ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.createAuthenticationData(mapNotifyBuilder.build(), "password"));
+        mapNotifyBuilder.getMappingRecordItem().add(
+                new MappingRecordItemBuilder().setMappingRecord(etlrBuilder.build()).build());
+        ArrayAssert.assertEquals(new byte[0], LispAuthenticationUtil.createAuthenticationData(mapNotifyBuilder.build(),
+                "password"));
 
     }
 
-    private Ipv4 asIPAfiAddress(String ip) {
-        return new Ipv4Builder().setIpv4Address(new Ipv4Address(ip)).setAfi((short) AddressFamilyNumberEnum.IP.getIanaCode()).build();
+    private static boolean validate(MapRegister mapRegister, Eid eid, int keyId, String password) {
+        MappingAuthkey key = new MappingAuthkeyBuilder().setKeyType(keyId).setKeyString(password).build();
+        return LispAuthenticationUtil.validate(mapRegister, eid, key);
     }
 }