diff options
6 files changed, 275 insertions, 8 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()); + + } +} diff --git a/ioam/ioam_postman_collection.json b/ioam/ioam_postman_collection.json index e79eab88b..abc0292f1 100644 --- a/ioam/ioam_postman_collection.json +++ b/ioam/ioam_postman_collection.json @@ -1,9 +1,9 @@ { "variables": [], "info": { - "name": "Honeycomb RESTCONF calls for iOAM Trace", + "name": "Honeycomb iOAM RESTCONF calls", "_postman_id": "014389fd-d55b-9b35-ad71-81eda31779bc", - "description": "To enable iOAM trace on VPP management nodes.", + "description": "To manage iOAM features on VPP management nodes.", "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json" }, "item": [ @@ -76,11 +76,36 @@ ], "body": { "mode": "raw", - "raw": "{\n\"pot-profile-set\":[\n\t\t{\n\t \"name\":\"potprofile\",\n\t \"path-identifier\":\"ACL\",\n\t \"active-profile-index\":1,\n\t \"pot-profile-list\":[{\n\t \t\"index\":1,\n\t \t\"prime-number\":7,\n\t \t\"secret-share\":1234,\n\t \t\"public-polynomial\":1234,\n\t \t\"lpc\":1234,\n\t \t\"validator\":\"true\",\n\t \t\"validator-key\":1234,\n\t \t\"bitmask\":1111111111\n\t }]\n\t }\n ]\n}\n" + "raw": "{\n\"pot-profile-set\":[\n\t\t{\n\t \"name\":\"potprofile\",\n\t \"path-identifier\":\"ACL\",\n\t \"active-profile-index\":1,\n\t \"pot-profile-list\":[{\n\t \t\"index\":0,\n\t \t\"prime-number\":7,\n\t \t\"secret-share\":1234,\n\t \t\"public-polynomial\":1234,\n\t \t\"lpc\":1234,\n\t \t\"validator\":\"true\",\n\t \t\"validator-key\":1234,\n\t \t\"bitmask\":1111111111\n\t }]\n\t }\n ]\n}\n" }, "description": "Configure ioam pot config on VPP" }, "response": [] + }, + { + "name": "iaom pot - oper", + "request": { + "url": "http://localhost:8183/restconf/operational/sfc-ioam-sb-pot:pot-profiles/pot-profile-set/potprofile/pot-profile-list/0", + "method": "GET", + "header": [ + { + "key": "Authorization", + "value": "Basic YWRtaW46YWRtaW4=", + "description": "" + }, + { + "key": "Content-Type", + "value": "application/json", + "description": "" + } + ], + "body": { + "mode": "raw", + "raw": "{\n\"trace-config\":{\n \"trace-config-name\":\"trace\",\n \"acl-name\":\"testAcl\",\n \"trace-type\":31,\n \"trace-num-elt\":3,\n \"trace-tsp\":\"milliseconds\",\n \"trace-op\":\"add\",\n \"trace-app-data\":1234,\n \"data-export-profile-name\":\"dataProfileName\",\n \"transport-encap-profile-name\":\"transProfileName\",\n \"node-id\":1,\n \"node-interfaces\":[\n {\n \"index\":5,\n \"intf-name\":\"GigabitEthernetb/0/0\"\n }\n ]\n }\n}\n" + }, + "description": "Read ioam pot config from VPP" + }, + "response": [] } ] }
\ No newline at end of file |