diff options
author | Michal Cmarada <michal.cmarada@pantheon.tech> | 2018-06-15 13:09:56 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-06-19 18:54:51 +0000 |
commit | 3edc384ac6cbeb68d36dbb4a51aa027c3bd3257d (patch) | |
tree | 78e4ae88f89e08756ae469d068c45e2e7a059c2f /srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid | |
parent | b44b5a2a1ee8ba193265708272be97fd6f11d010 (diff) |
HC2VPP-288 - add SRv6 module (writers only)
Changes:
- add new module for SRv6
- add models for SRv6 configuration:
from https://datatracker.ietf.org/doc/draft-raza-spring-srv6-yang/
- hc2vpp-ietf-srv6-base@2018-03-01.yang
- hc2vpp-ietf-srv6-static@2018-03-01.yang
- ietf-srv6-types@2018-03-01.yang
- implements Configuration of local sids and their end functions.
- implements support for FIB table management (HC2VPP-345)
Models hc2vpp-ietf-srv6-base and hc2vpp-ietf-srv6-static
are changed (HC2VPP-332):
- imports for routing models (HC2VPP-298)
- presence in end function containers was added to fix
mandatory child verification if parent container is not present
Change-Id: Ib74e48023b671383f076b84773e26ce7c5ae282a
Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Signed-off-by: Jan Srnicek <jan.srnicek@pantheon.tech>
Diffstat (limited to 'srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid')
6 files changed, 479 insertions, 0 deletions
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java new file mode 100644 index 000000000..86ab3599c --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/LocatorCustomizer.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid; + +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.Locator; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.LocatorKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class LocatorCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Locator, LocatorKey> { + + public LocatorCustomizer(@Nonnull final FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Locator> instanceIdentifier, + @Nonnull final Locator locator, @Nonnull final WriteContext writeContext) { + // noop + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Locator> instanceIdentifier, + @Nonnull final Locator locator, @Nonnull final WriteContext writeContext) { + // noop + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java new file mode 100644 index 000000000..c63205699 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/SidCustomizer.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid; + +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.googlecode.ipv6.IPv6NetworkMask; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionWriteBindingRegistry; +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest; +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.ietf.srv6.base.rev180613.VppSrv6FibLocatorAugment; +import org.opendaylight.yang.gen.v1.urn.hc2vpp.params.xml.ns.yang.vpp.ietf.srv6.base.rev180613.vpp.srv6.fib.FibTable; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.SidKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.Locator; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.base.rev180301.srv6.locators.locators.locator.Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.vpp.fib.table.management.fib.tables.TableKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +public class SidCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<Sid, SidKey> { + + private final LocalSidFunctionWriteBindingRegistry bindingRegistry; + + public SidCustomizer(@Nonnull final FutureJVppCore futureJVppCore, + @Nonnull final LocalSidFunctionWriteBindingRegistry bindingRegistry) { + super(futureJVppCore); + this.bindingRegistry = bindingRegistry; + } + + Ipv6Address resolveSidAddress(@Nonnull final Prefix locPrefix, @Nonnull Sid localSid) { + com.googlecode.ipv6.IPv6Address ip = + com.googlecode.ipv6.IPv6Address.fromString(locPrefix.getAddress().getValue()); + IPv6NetworkMask mask = IPv6NetworkMask.fromPrefixLength(locPrefix.getLength().getValue()); + // strip function part if present + ip = ip.maskWithNetworkMask(mask); + //add new function part based on opcode + String locIp = ip.add(localSid.getOpcode().getValue().intValue()).toString(); + return new Ipv6Address(locIp); + } + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Sid> instanceIdentifier, + @Nonnull final Sid localSid, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + InstanceIdentifier<Locator> locatorIid = RWUtils.cutId(instanceIdentifier, Locator.class); + Optional<Locator> locatorOpt = writeContext.readAfter(locatorIid); + Table vrfTable = getVrfTable(instanceIdentifier, writeContext, locatorIid, locatorOpt); + LocalSidFunctionRequest request = bindRequest(extractLocPrefix(instanceIdentifier, locatorOpt, localSid), + localSid, vrfTable.getTableId().getValue().intValue(), writeContext); + if (request == null) { + throw new WriteFailedException(instanceIdentifier, + String.format("Cannot create write request for %s", localSid)); + } + request.write(instanceIdentifier); + } + + private Table getVrfTable(final @Nonnull InstanceIdentifier<Sid> iid, final @Nonnull WriteContext writeContext, + final InstanceIdentifier<Locator> locatorIid, final Optional<Locator> locatorOpt) { + Preconditions.checkArgument(locatorOpt.isPresent(), "Locator: {} for SID: {} was not found.", locatorIid, iid); + Preconditions.checkNotNull(locatorOpt.get().getAugmentation(VppSrv6FibLocatorAugment.class), + "Vpp FIB table augmentation was not found for SID: {}.", iid); + FibTable fibTable = locatorOpt.get().getAugmentation(VppSrv6FibLocatorAugment.class).getFibTable(); + Preconditions.checkNotNull(fibTable, "Vpp FIB table configuration was not found for SID: {}.", iid); + TableKey tableKey = new TableKey(fibTable.getAddressFamily(), fibTable.getTableId()); + KeyedInstanceIdentifier<Table, TableKey> vrfIid = FibManagementIIds.FM_FIB_TABLES.child(Table.class, tableKey); + if (!writeContext.readAfter(vrfIid).isPresent()) { + throw new IllegalArgumentException( + String.format("VRF table: %s not found. Create table before writing SID : %s.", tableKey, iid)); + } + return writeContext.readAfter(vrfIid).get(); + } + + private Prefix extractLocPrefix(final @Nonnull InstanceIdentifier<Sid> instanceIdentifier, + Optional<Locator> locatorOpt, final @Nonnull Sid localSid) + throws WriteFailedException { + Preconditions.checkArgument(locatorOpt.isPresent(), "Cannot read locator for sid: {}, with IId: ", localSid, + instanceIdentifier); + Locator loc = locatorOpt.get(); + if (loc.getPrefix() == null || loc.getPrefix() == null || loc.getPrefix().getAddress() == null || + loc.getPrefix().getLength() == null) { + throw new WriteFailedException(instanceIdentifier, + String.format("Cannot parse locator prefix for local sid %s", localSid)); + } + return loc.getPrefix(); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Sid> instanceIdentifier, + @Nonnull final Sid localSid, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + InstanceIdentifier<Locator> locatorIid = RWUtils.cutId(instanceIdentifier, Locator.class); + Optional<Locator> locatorOpt = writeContext.readBefore(locatorIid); + Table vrfTable = getVrfTable(instanceIdentifier, writeContext, locatorIid, locatorOpt); + LocalSidFunctionRequest request = bindRequest(extractLocPrefix(instanceIdentifier, locatorOpt, localSid), + localSid, vrfTable.getTableId().getValue().intValue(), writeContext); + + if (request == null) { + throw new WriteFailedException(instanceIdentifier, + String.format("Cannot create delete request for %s", localSid)); + } + request.delete(instanceIdentifier); + } + + private LocalSidFunctionRequest bindRequest(final @Nonnull Prefix locPrefix, final @Nonnull Sid localSid, + final int installFibId, final @Nonnull WriteContext writeContext) { + LocalSidFunctionRequest request = bindingRegistry.bind(localSid, writeContext); + Ipv6Address sidAddress = resolveSidAddress(locPrefix, localSid); + request.setLocalSidAddress(sidAddress); + request.setInstallFibTable(installFibId); + return request; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java new file mode 100644 index 000000000..e3d64ea6c --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/LocalSidFunctionRequest.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import io.fd.hc2vpp.srv6.util.JVppRequest; +import io.fd.hc2vpp.srv6.write.DeleteRequest; +import io.fd.hc2vpp.srv6.write.WriteRequest; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import io.fd.vpp.jvpp.core.types.Srv6Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.Srv6SidConfig; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * General template for Local SID requests + */ +public abstract class LocalSidFunctionRequest<O extends ChildOf<Srv6SidConfig>> extends JVppRequest + implements WriteRequest, DeleteRequest { + + /** + * Local SID + */ + private Ipv6Address localSidAddress; + + /** + * FIB table where Local SID will be installed + */ + private int installFibTable; + + /** + * Function that will be used for this Local SID + */ + private int function; + + /** + * Whether this node should remove segment routing header for incoming packets + */ + private boolean isPsp; + + LocalSidFunctionRequest(final FutureJVppCore api) { + super(api); + //Default behaviour is PSP. END,END.T and END.X function can set USP=true -> PSP=false + isPsp = true; + } + + protected void bindRequest(final SrLocalsidAddDel request) { + Srv6Sid srv6Sid = new Srv6Sid(); + srv6Sid.addr = ipv6AddressNoZoneToArray(getLocalSidAddress()); + request.localsid = srv6Sid; + request.behavior = (byte) getFunction(); + request.fibTable = getInstallFibTable(); + request.endPsp = booleanToByte(isPsp()); + } + + @Override + public void checkValid() { + checkNotNull(getLocalSidAddress(), "Sid address not set"); + checkState(getFunction() != 0, "No behavior set"); + } + + @Override + public void write(final InstanceIdentifier<?> identifier) throws WriteFailedException { + checkValid(); + + final SrLocalsidAddDel request = new SrLocalsidAddDel(); + request.isDel = 0; + bindRequest(request); + + getReplyForWrite(getApi().srLocalsidAddDel(request).toCompletableFuture(), identifier); + } + + @Override + public void delete(final InstanceIdentifier<?> identifier) throws WriteFailedException { + checkValid(); + + final SrLocalsidAddDel request = new SrLocalsidAddDel(); + request.isDel = 1; + bindRequest(request); + getReplyForDelete(getApi().srLocalsidAddDel(request).toCompletableFuture(), identifier); + } + + public Ipv6Address getLocalSidAddress() { + return localSidAddress; + } + + public void setLocalSidAddress(final Ipv6Address localSidAddress) { + this.localSidAddress = localSidAddress; + } + + public int getInstallFibTable() { + return installFibTable; + } + + public void setInstallFibTable(final int installFibTable) { + this.installFibTable = installFibTable; + } + + public int getFunction() { + return function; + } + + public void setFunction(final int function) { + this.function = function; + } + + public boolean isPsp() { + return isPsp; + } + + public void setPsp(final boolean psp) { + isPsp = psp; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java new file mode 100644 index 000000000..18630ccc2 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/NoProtocolLocalSidRequest.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +/** + * Local SID using End function + */ +public class NoProtocolLocalSidRequest extends LocalSidFunctionRequest { + + public NoProtocolLocalSidRequest(final FutureJVppCore api) { + super(api); + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java new file mode 100644 index 000000000..4642b3349 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/TableLookupLocalSidRequest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +/** + * Request for Local SID using table lookup functions + */ +public class TableLookupLocalSidRequest extends LocalSidFunctionRequest { + + /** + * FIB table where table lookup should be performed + */ + private int lookupFibTable; + + public TableLookupLocalSidRequest(final FutureJVppCore api) { + super(api); + } + + @Override + protected void bindRequest(final SrLocalsidAddDel request) { + super.bindRequest(request); + request.swIfIndex = getLookupFibTable(); + } + + public int getLookupFibTable() { + return lookupFibTable; + } + + public void setLookupFibTable(final int lookupFibTable) { + this.lookupFibTable = lookupFibTable; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java new file mode 100644 index 000000000..38208aaf1 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/write/sid/request/XConnectLocalSidRequest.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.srv6.write.sid.request; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.vpp.jvpp.core.dto.SrLocalsidAddDel; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; + +/** + * Request for Local SID that should use x-connect functions + */ +public class XConnectLocalSidRequest extends LocalSidFunctionRequest { + + /** + * L2 interface that should be use for forwarding traffic + */ + private int outgoingInterfaceIndex; + + /** + * Outgoing VLan tag + */ + private int vlanIndex; + + /** + * Address of the next hop + */ + private IpAddress nextHopAddress; + + public XConnectLocalSidRequest(final FutureJVppCore api) { + super(api); + } + + @Override + protected void bindRequest(final SrLocalsidAddDel request) { + super.bindRequest(request); + request.swIfIndex = getOutgoingInterfaceIndex(); + request.vlanIndex = getVlanIndex(); + if (getNextHopAddress() != null) { + if (AddressTranslator.INSTANCE.isIpv6(getNextHopAddress())) { + request.nhAddr6 = ipAddressToArray(getNextHopAddress()); + } else { + request.nhAddr4 = ipAddressToArray(getNextHopAddress()); + + } + + } + } + + public int getOutgoingInterfaceIndex() { + return outgoingInterfaceIndex; + } + + public void setOutgoingInterfaceIndex(final int outgoingInterfaceIndex) { + this.outgoingInterfaceIndex = outgoingInterfaceIndex; + } + + public int getVlanIndex() { + return vlanIndex; + } + + public void setVlanIndex(final int vlanIndex) { + this.vlanIndex = vlanIndex; + } + + public IpAddress getNextHopAddress() { + return nextHopAddress; + } + + public void setNextHopAddress(final IpAddress nextHopAddress) { + this.nextHopAddress = nextHopAddress; + } +} |