summaryrefslogtreecommitdiffstats
path: root/ioam/impl
diff options
context:
space:
mode:
authorSagar Srivastav <sagsriva@cisco.com>2016-12-14 05:24:19 -0800
committerMarek Gradzki <mgradzki@cisco.com>2016-12-19 07:40:32 +0000
commit6b134b926aa30931dbf02ad6c596078a50666144 (patch)
tree5445e76cd4914e4ebebb5b73e1174aaf04f3dff9 /ioam/impl
parentc5894b0fe3036763702003adc8421c2e715c90b6 (diff)
ioam: Reader/Initializer for POT plugin
- reader/initializer for pot - pot read call in postman collection Change-Id: I1e8f80449897c1ee5289f39eb7d75acb351eb255 Signed-off-by: Sagar Srivastav <sagsriva@cisco.com>
Diffstat (limited to 'ioam/impl')
-rw-r--r--ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizer.java13
-rw-r--r--ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizer.java115
-rw-r--r--ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/VppIoamReaderFactory.java25
-rw-r--r--ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizerTest.java4
-rw-r--r--ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizerTest.java95
5 files changed, 247 insertions, 5 deletions
diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizer.java
index 6d80493a3..c5868decf 100644
--- a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizer.java
+++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizer.java
@@ -26,6 +26,7 @@ import io.fd.vpp.jvpp.ioampot.dto.PotProfileAddReply;
import io.fd.vpp.jvpp.ioampot.dto.PotProfileDel;
import io.fd.vpp.jvpp.ioampot.dto.PotProfileDelReply;
import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot;
+import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileList;
@@ -125,11 +126,10 @@ public class IoamPotWriterCustomizer extends FutureJVppIoampotCustomizer impleme
PotProfileAdd request = new PotProfileAdd();
request.id = potProfileList.getIndex().getValue().byteValue();
request.validator = (byte) (potProfileList.isValidator() ? 1 : 0);
- request.secretKey = 1;
request.secretShare = potProfileList.getSecretShare().longValue();
request.prime = potProfileList.getPrimeNumber().longValue();
request.secretKey = potProfileList.getValidatorKey().longValue();
- request.maxBits = 64;
+ request.maxBits = getMaxBitsfromBitmask(potProfileList.getBitmask());
request.lpc = potProfileList.getLpc().longValue();
request.polynomialPublic = potProfileList.getPublicPolynomial().longValue();
request.listNameLen = (byte) name.getBytes(StandardCharsets.UTF_8).length;
@@ -146,4 +146,13 @@ public class IoamPotWriterCustomizer extends FutureJVppIoampotCustomizer impleme
return getReplyForWrite(getFutureJVppIoampot().potProfileDel(request).toCompletableFuture(),id);
}
+
+ static byte getMaxBitsfromBitmask(BigInteger bitmask){
+ byte numOfBits = 0;
+ while ((bitmask.and(BigInteger.ONE)).equals(BigInteger.ONE)){
+ bitmask=bitmask.shiftRight(1);
+ numOfBits++;
+ }
+ return numOfBits;
+ }
}
diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizer.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizer.java
new file mode 100644
index 000000000..43a589c35
--- /dev/null
+++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizer.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vppioam.impl.oper;
+
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.vppioam.impl.util.FutureJVppIoampotCustomizer;
+import io.fd.honeycomb.translate.read.ReadContext;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.Initialized;
+import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer;
+import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDetails;
+import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDetailsReplyDump;
+import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDump;
+import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import javax.annotation.Nonnull;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.ProfileIndexRange;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileList;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileListBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileListKey;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profiles.PotProfileSetBuilder;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PotProfileReaderCustomizer extends FutureJVppIoampotCustomizer implements JvppReplyConsumer,
+ InitializingListReaderCustomizer<PotProfileList,PotProfileListKey,PotProfileListBuilder> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PotProfileReaderCustomizer.class);
+
+ public PotProfileReaderCustomizer(FutureJVppIoampot futureJVppIoampot){
+ super(futureJVppIoampot);
+ }
+
+ @Nonnull
+ @Override
+ public Initialized<? extends DataObject> init(@Nonnull final InstanceIdentifier<PotProfileList> instanceIdentifier,
+ @Nonnull final PotProfileList potProfileList,
+ @Nonnull final ReadContext readContext) {
+ return Initialized.create(instanceIdentifier,new PotProfileListBuilder(potProfileList).build());
+ }
+
+ @Nonnull
+ @Override
+ public List<PotProfileListKey> getAllIds(@Nonnull final InstanceIdentifier<PotProfileList> instanceIdentifier,
+ @Nonnull final ReadContext readContext) throws ReadFailedException {
+
+ //vpp will always return 2 entries with id's 0 and 1
+ //will contain 0 values if not previously configured
+
+ List<PotProfileListKey> allIds = new ArrayList<>(2);
+ allIds.add(new PotProfileListKey(new ProfileIndexRange(0)));
+ allIds.add(new PotProfileListKey(new ProfileIndexRange(1)));
+ return allIds;
+ }
+
+ @Override
+ public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<PotProfileList> list) {
+ ((PotProfileSetBuilder)builder).setPotProfileList(list);
+ }
+
+ @Nonnull
+ @Override
+ public PotProfileListBuilder getBuilder(@Nonnull final InstanceIdentifier<PotProfileList> instanceIdentifier) {
+ return new PotProfileListBuilder();
+ }
+
+ @Override
+ public void readCurrentAttributes(@Nonnull final InstanceIdentifier<PotProfileList> instanceIdentifier,
+ @Nonnull final PotProfileListBuilder builder,
+ @Nonnull final ReadContext readContext) throws ReadFailedException {
+ final PotProfileShowConfigDump request = new PotProfileShowConfigDump();
+ PotProfileListKey key = instanceIdentifier.firstKeyOf(PotProfileList.class);
+ request.id = key.getIndex().getValue().byteValue();
+ final PotProfileShowConfigDetailsReplyDump reply = getReplyForRead(getFutureJVppIoampot()
+ .potProfileShowConfigDump(request)
+ .toCompletableFuture(), instanceIdentifier);
+
+ if (reply == null || reply.potProfileShowConfigDetails == null || reply.potProfileShowConfigDetails.isEmpty()) {
+ LOG.debug("Vpp returned no pot profiles");
+ return;
+ }
+
+ final PotProfileShowConfigDetails details = reply.potProfileShowConfigDetails.get(0);
+
+ builder.setValidator(details.validator==1);
+ builder.setValidatorKey(BigInteger.valueOf(details.secretKey));
+ builder.setSecretShare(BigInteger.valueOf(details.secretShare));
+ builder.setPrimeNumber(BigInteger.valueOf(details.prime));
+ builder.setPublicPolynomial(BigInteger.valueOf(details.polynomialPublic));
+ builder.setIndex(new ProfileIndexRange((int)details.id));
+ builder.setLpc(BigInteger.valueOf(details.lpc));
+ builder.setBitmask(BigInteger.valueOf(details.bitMask));
+
+ LOG.info("Item {} successfully read: {}",instanceIdentifier,builder.build());
+ }
+}
diff --git a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/VppIoamReaderFactory.java b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/VppIoamReaderFactory.java
index 83fd5667a..26c1a8a99 100644
--- a/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/VppIoamReaderFactory.java
+++ b/ioam/impl/src/main/java/io/fd/hc2vpp/vppioam/impl/oper/VppIoamReaderFactory.java
@@ -18,22 +18,32 @@ package io.fd.hc2vpp.vppioam.impl.oper;
import io.fd.honeycomb.translate.impl.read.GenericInitListReader;
import io.fd.honeycomb.translate.read.ReaderFactory;
import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
+import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot;
import io.fd.vpp.jvpp.ioamtrace.future.FutureJVppIoamtrace;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfig;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.IoamTraceConfigBuilder;
import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.ioam.sb.trace.rev160512.ioam.trace.config.TraceConfig;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.PotProfiles;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.PotProfilesBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileList;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profiles.PotProfileSet;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profiles.PotProfileSetBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class VppIoamReaderFactory implements ReaderFactory {
+ @Nonnull
FutureJVppIoamtrace jVppIoamtrace;
+ @Nonnull
+ FutureJVppIoampot jVppIoampot;
@Inject
- VppIoamReaderFactory(FutureJVppIoamtrace jVppIoamtrace){
+ VppIoamReaderFactory(FutureJVppIoamtrace jVppIoamtrace, FutureJVppIoampot jVppIoampot){
this.jVppIoamtrace = jVppIoamtrace;
+ this.jVppIoampot = jVppIoampot;
}
/**
@@ -52,5 +62,18 @@ public class VppIoamReaderFactory implements ReaderFactory {
final InstanceIdentifier<TraceConfig> traceConfigId = ioamTraceConfigId.child(TraceConfig.class);
registry.add(new GenericInitListReader<>(traceConfigId,
new TraceProfileReaderCustomizer(jVppIoamtrace)));
+
+ //PotProfiles (Structural)
+ final InstanceIdentifier<PotProfiles> potProfilesInstanceIdentifier = InstanceIdentifier.create(PotProfiles.class);
+ registry.addStructuralReader(potProfilesInstanceIdentifier, PotProfilesBuilder.class);
+ //PotProfileSet (Structural)
+ final InstanceIdentifier<PotProfileSet> potProfileSetInstanceIdentifier =
+ potProfilesInstanceIdentifier.child(PotProfileSet.class);
+ registry.addStructuralReader(potProfileSetInstanceIdentifier, PotProfileSetBuilder.class);
+ //PotProfileList
+ final InstanceIdentifier<PotProfileList> potProfileListInstanceIdentifier= potProfileSetInstanceIdentifier.child(PotProfileList.class);
+ registry.add(new GenericInitListReader<>(potProfileListInstanceIdentifier,
+ new PotProfileReaderCustomizer(jVppIoampot)));
+
}
}
diff --git a/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizerTest.java b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizerTest.java
index eccfd5d50..c32101698 100644
--- a/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizerTest.java
+++ b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/config/IoamPotWriterCustomizerTest.java
@@ -61,7 +61,7 @@ public class IoamPotWriterCustomizerTest extends WriterCustomizerTest {
private static PotProfileList generatePotProfileList() {
final PotProfileListBuilder builder= new PotProfileListBuilder();
builder.setIndex(new ProfileIndexRange(1));
- builder.setBitmask(new BigInteger("1"));
+ builder.setBitmask(new BigInteger("64"));
builder.setKey(new PotProfileListKey(new ProfileIndexRange(1)));
builder.setLpc(new BigInteger("1233"));
builder.setPrimeNumber(new BigInteger("1001"));
@@ -115,7 +115,7 @@ public class IoamPotWriterCustomizerTest extends WriterCustomizerTest {
request.secretKey = 1;
request.secretShare = 1234;
request.prime = 1001;
- request.maxBits = 64;
+ request.maxBits = IoamPotWriterCustomizer.getMaxBitsfromBitmask(BigInteger.valueOf(64));
request.lpc = 1233;
request.polynomialPublic = 1234;
request.listNameLen = (byte)POT_TEST_NAME.getBytes(StandardCharsets.UTF_8).length;
diff --git a/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizerTest.java b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizerTest.java
new file mode 100644
index 000000000..f0c3f83d1
--- /dev/null
+++ b/ioam/impl/src/test/java/io/fd/hc2vpp/vppioam/impl/oper/PotProfileReaderCustomizerTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.hc2vpp.vppioam.impl.oper;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+
+import com.google.common.collect.Lists;
+import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest;
+import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.spi.read.ReaderCustomizer;
+import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDetails;
+import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDetailsReplyDump;
+import io.fd.vpp.jvpp.ioampot.dto.PotProfileShowConfigDump;
+import io.fd.vpp.jvpp.ioampot.future.FutureJVppIoampot;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.PotProfiles;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.ProfileIndexRange;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileList;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileListBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profile.PotProfileListKey;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profiles.PotProfileSet;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profiles.PotProfileSetBuilder;
+import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.sfc.ioam.sb.pot.rev160615.pot.profiles.PotProfileSetKey;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class PotProfileReaderCustomizerTest extends ListReaderCustomizerTest<PotProfileList,PotProfileListKey,
+ PotProfileListBuilder>{
+
+ @Mock
+ FutureJVppIoampot jVppIoampot;
+
+ public PotProfileReaderCustomizerTest(){
+ super(PotProfileList.class, PotProfileSetBuilder.class);
+ }
+
+ @Override
+ protected ReaderCustomizer<PotProfileList, PotProfileListBuilder> initCustomizer() {
+ return new PotProfileReaderCustomizer(jVppIoampot);
+ }
+
+ @Override
+ public void setUp(){
+ final PotProfileShowConfigDetailsReplyDump replyDump = new PotProfileShowConfigDetailsReplyDump();
+ final PotProfileShowConfigDetails replyDetails = new PotProfileShowConfigDetails();
+ replyDetails.bitMask = (long)0xFFFFFF;
+ replyDetails.id=0;
+ replyDetails.lpc=1234;
+ replyDetails.polynomialPublic=1234;
+ replyDetails.prime=7;
+ replyDetails.secretKey=1234;
+ replyDetails.secretShare = 1234;
+ replyDetails.validator = 1;
+ replyDump.potProfileShowConfigDetails = Lists.newArrayList(replyDetails);
+ doReturn(future(replyDump)).when(jVppIoampot).potProfileShowConfigDump(any(PotProfileShowConfigDump.class));
+ }
+
+ private InstanceIdentifier<PotProfileList> getPotProfileListId(int id){
+ return InstanceIdentifier.create(PotProfiles.class)
+ .child(PotProfileSet.class, new PotProfileSetKey("potprofile"))
+ .child(PotProfileList.class, new PotProfileListKey(new ProfileIndexRange(id)));
+ }
+
+ @Test
+ public void testReadCurrentAttributes() throws ReadFailedException {
+ PotProfileListBuilder builder = new PotProfileListBuilder();
+ getCustomizer().readCurrentAttributes(getPotProfileListId(0),builder,ctx);
+ assertEquals(0xFFFFFF,builder.getBitmask().longValue());
+ assertEquals(0,builder.getIndex().getValue().intValue());
+ assertEquals(1234,builder.getLpc().longValue());
+ assertEquals(1234,builder.getPublicPolynomial().longValue());
+ assertEquals(7,builder.getPrimeNumber().longValue());
+ assertEquals(1234,builder.getValidatorKey().longValue());
+ assertEquals(1234,builder.getSecretShare().longValue());
+ assertEquals(true,builder.isValidator());
+
+ }
+}