diff options
Diffstat (limited to 'srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util')
15 files changed, 829 insertions, 0 deletions
diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java new file mode 100644 index 000000000..9ea9fff30 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/JVppRequest.java @@ -0,0 +1,38 @@ +/* + * 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.util; + +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; + +public abstract class JVppRequest implements AddressTranslator, JvppReplyConsumer { + + private final FutureJVppCore api; + + protected JVppRequest(final FutureJVppCore api) { + this.api = api; + } + + protected FutureJVppCore getApi() { + return api; + } + + public void checkValid() { + //noop + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java new file mode 100644 index 000000000..e51ee5ac5 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBinder.java @@ -0,0 +1,70 @@ +/* + * 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.util.function; + +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +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.types.rev180301.Srv6EndpointType; + +/** + * Binder interface, which is used to map yang model data classes of local sid functions to local sid function requests + * used to configure endpoint functions on VPP. It uses behavior function type integer value defined by VPP API, to find + * suitable binder. This value is translated to {@link Srv6EndpointType} in model, which represents the same endpoint + * function as defined by VPP API. + * + * @param <T> Type which extends general interface for {@link LocalSidFunctionRequest} and represents template binder + * that is used to process end function data represented by provided class type. + */ +public interface LocalSidFunctionBinder<T extends LocalSidFunctionRequest> { + + /** + * Binds request accordingly to type of function implemented by this interface + * + * @return request with all attributes necessary for this function + */ + @Nonnull + T createWriteRequestAndBind(@Nonnull final Sid data, @Nonnull final WriteContext ctx); + + /** + * Provides Endpoint function type class. + * @return Endpoint function class + */ + @Nonnull + Class<? extends Srv6EndpointType> getHandledFunctionType(); + + /** + * Provide behavior function type integer value. + * + * @return integer value of behaviour function type as defined in VPP api + */ + int getBehaviourFunctionType(); + + /** + * Checks whether binder can handle provided data + * + * @param data sid function data to be checked + * @return true if function binder is able to process provided data, false otherwise + */ + default boolean canHandle(final Sid data) { + if (data == null || data.getEndBehaviorType() == null) { + return false; + } + return data.getEndBehaviorType().equals(getHandledFunctionType()); + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java new file mode 100644 index 000000000..d56656fb9 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionBindingRegistry.java @@ -0,0 +1,50 @@ +/* + * 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.util.function; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nonnull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +abstract class LocalSidFunctionBindingRegistry<T extends LocalSidFunctionRequest> { + + private static final Logger LOG = LoggerFactory.getLogger(LocalSidFunctionBindingRegistry.class); + final List<LocalSidFunctionBinder<T>> binders; + + LocalSidFunctionBindingRegistry() { + binders = new ArrayList<>(); + } + + @SuppressWarnings("unchecked") + public void registerFunctionType(@Nonnull final LocalSidFunctionBinder binder) { + checkNotNull(binder, "Cannot register null binder"); + if (!isFunctionRegistered(binder)) { + binders.add(binder); + } else { + LOG.warn("Binder for class already registered. Canceling registration for {}.", binder); + } + } + + private boolean isFunctionRegistered(@Nonnull final LocalSidFunctionBinder binder) { + return binders.stream().parallel().anyMatch(locBinder -> locBinder.getClass().equals(binder.getClass())); + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java new file mode 100644 index 000000000..b74a7668b --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistry.java @@ -0,0 +1,34 @@ +/* + * 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.util.function; + +import io.fd.hc2vpp.srv6.write.sid.request.LocalSidFunctionRequest; +import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.honeycomb.translate.write.WriteContext; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.srv6._static.cfg.Sid; + +public class LocalSidFunctionWriteBindingRegistry<T extends LocalSidFunctionRequest> + extends LocalSidFunctionBindingRegistry<T> { + + public LocalSidFunctionRequest bind(final Sid localSid, @Nonnull final WriteContext ctx) { + return binders.parallelStream() + .filter(toLocalSidFunctionBinder -> toLocalSidFunctionBinder.canHandle(localSid)) + .map(binder -> binder.createWriteRequestAndBind(localSid, ctx)) + .collect(RWUtils.singleItemCollector()); + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java new file mode 100644 index 000000000..20189b702 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/LocalSidFunctionWriteBindingRegistryProvider.java @@ -0,0 +1,56 @@ +/* + * 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.util.function; + +import com.google.inject.Inject; +import com.google.inject.Provider; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.util.function.lookup.EndDT4FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.lookup.EndDT6FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.lookup.EndTFunctionBinder; +import io.fd.hc2vpp.srv6.util.function.nofunction.EndFunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX2FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX4FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndDX6FunctionBinder; +import io.fd.hc2vpp.srv6.util.function.xconnect.EndXFunctionBinder; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import javax.inject.Named; + +public class LocalSidFunctionWriteBindingRegistryProvider implements Provider<LocalSidFunctionWriteBindingRegistry> { + + @Inject + @Named("interface-context") + private NamingContext interfaceContext; + + @Inject + private FutureJVppCore api; + private final LocalSidFunctionWriteBindingRegistry registry = new LocalSidFunctionWriteBindingRegistry(); + + @Override + public LocalSidFunctionWriteBindingRegistry get() { + registry.registerFunctionType(new EndFunctionBinder(api)); + registry.registerFunctionType(new EndTFunctionBinder(api)); + registry.registerFunctionType(new EndDT4FunctionBinder(api)); + registry.registerFunctionType(new EndDT6FunctionBinder(api)); + registry.registerFunctionType(new EndXFunctionBinder(api, interfaceContext)); + registry.registerFunctionType(new EndDX2FunctionBinder(api, interfaceContext)); + registry.registerFunctionType(new EndDX4FunctionBinder(api, interfaceContext)); + registry.registerFunctionType(new EndDX6FunctionBinder(api, interfaceContext)); + + return registry; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.java new file mode 100644 index 000000000..e8ea22419 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT4FunctionBinder.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.util.function.lookup; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest; +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._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndDT4FunctionBinder extends TableLookupFunctionBinder { + + public EndDT4FunctionBinder(@Nonnull final FutureJVppCore api) { + super(api); + } + + @Nonnull + @Override + public TableLookupLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, + @Nonnull WriteContext ctx) { + Preconditions.checkNotNull(data.getEndDt4(), "EndDt4 data cannot be null."); + Preconditions.checkNotNull(data.getEndDt4().getLookupTableIpv4(), "EndDt4 lookup table cannot be null."); + int lookupTable = data.getEndDt4().getLookupTableIpv4().getValue().intValue(); + return bindData(new TableLookupLocalSidRequest(getFutureJVpp()), lookupTable, false, ctx); + } + + @Override + @Nonnull + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return EndDT4.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.java new file mode 100644 index 000000000..01e6c6bb2 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndDT6FunctionBinder.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.util.function.lookup; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest; +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._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndDT6FunctionBinder extends TableLookupFunctionBinder { + + public EndDT6FunctionBinder(@Nonnull final FutureJVppCore api) { + super(api); + } + + @Nonnull + @Override + public TableLookupLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, + @Nonnull WriteContext ctx) { + Preconditions.checkNotNull(data.getEndDt6(), "EndDt6 data cannot be null."); + Preconditions.checkNotNull(data.getEndDt6().getLookupTableIpv6(), "EndDt6 lookup table cannot be null."); + int lookupTable = data.getEndDt6().getLookupTableIpv6().getValue().intValue(); + return bindData(new TableLookupLocalSidRequest(getFutureJVpp()), lookupTable, true, ctx); + } + + @Override + @Nonnull + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return EndDT6.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java new file mode 100644 index 000000000..13a2d3bc7 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/EndTFunctionBinder.java @@ -0,0 +1,47 @@ +/* + * 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.util.function.lookup; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest; +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._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndTFunctionBinder extends TableLookupFunctionBinder { + + public EndTFunctionBinder(@Nonnull FutureJVppCore api) { + super(api); + } + + @Nonnull + @Override + public TableLookupLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, @Nonnull WriteContext ctx) { + Preconditions.checkNotNull(data.getEndT(), "EndT data cannot be null."); + Preconditions.checkNotNull(data.getEndT().getLookupTableIpv6(), "EndT lookup table cannot be null."); + int lookupTable = data.getEndT().getLookupTableIpv6().getValue().intValue(); + return bindData(new TableLookupLocalSidRequest(getFutureJVpp()), lookupTable, true, ctx); + } + + @Override + @Nonnull + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java new file mode 100644 index 000000000..8e6ab4f40 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/lookup/TableLookupFunctionBinder.java @@ -0,0 +1,76 @@ +/* + * 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.util.function.lookup; + +import static com.google.common.base.Preconditions.checkState; + +import com.google.common.collect.ImmutableMap; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.fib.management.FibManagementIIds; +import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionBinder; +import io.fd.hc2vpp.srv6.write.sid.request.TableLookupLocalSidRequest; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Map; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDT6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndT; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.AddressFamilyIdentity; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv4; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.Ipv6; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.fib.table.management.rev180521.VniReference; +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.KeyedInstanceIdentifier; + +abstract class TableLookupFunctionBinder extends FutureJVppCustomizer + implements LocalSidFunctionBinder<TableLookupLocalSidRequest> { + + private static final Map<Class<? extends Srv6EndpointType>, Integer> REGISTER = ImmutableMap.of( + EndT.class, 3, + EndDT6.class, 8, + EndDT4.class, 9 + ); + + TableLookupFunctionBinder(@Nonnull final FutureJVppCore api) { + super(api); + checkState(REGISTER.containsKey(getHandledFunctionType()), + "Unsupported type of Local SID function %s", getHandledFunctionType()); + } + + TableLookupLocalSidRequest bindData(TableLookupLocalSidRequest request, int tableIndex, final boolean isIpv6, + WriteContext ctx) { + // verify if the lookup table exists + Class<? extends AddressFamilyIdentity> adrFamily = isIpv6 ? Ipv6.class : Ipv4.class; + TableKey tableKey = new TableKey(adrFamily, new VniReference(Integer.toUnsignedLong(tableIndex))); + KeyedInstanceIdentifier<Table, TableKey> vrfIid = FibManagementIIds.FM_FIB_TABLES.child(Table.class, tableKey); + if (!ctx.readAfter(vrfIid).isPresent()) { + throw new IllegalArgumentException( + String.format("VRF lookup table: %s not found. Binding failed for request: %s", tableKey, request)); + } + request.setLookupFibTable(tableIndex); + request.setFunction(getBehaviourFunctionType()); + return request; + } + + @Override + public int getBehaviourFunctionType() { + return REGISTER.get(getHandledFunctionType()); + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java new file mode 100644 index 000000000..a1952e3c4 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/nofunction/EndFunctionBinder.java @@ -0,0 +1,58 @@ +/* + * 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.util.function.nofunction; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionBinder; +import io.fd.hc2vpp.srv6.write.sid.request.NoProtocolLocalSidRequest; +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._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndFunctionBinder extends FutureJVppCustomizer implements + LocalSidFunctionBinder<NoProtocolLocalSidRequest> { + + private static final int END_FUNCTION_VALUE = 1; + + public EndFunctionBinder(@Nonnull FutureJVppCore futureJVppCore) { + super(futureJVppCore); + } + + @Nonnull + @Override + public NoProtocolLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, + @Nonnull WriteContext ctx) { + Preconditions.checkNotNull(data.getEnd(), "End data cannot be null."); + NoProtocolLocalSidRequest request = new NoProtocolLocalSidRequest(getFutureJVpp()); + request.setFunction(END_FUNCTION_VALUE); + return request; + } + + @Nonnull + @Override + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.End.class; + } + + @Override + public int getBehaviourFunctionType() { + return END_FUNCTION_VALUE; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java new file mode 100644 index 000000000..63de40b9c --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX2FunctionBinder.java @@ -0,0 +1,56 @@ +/* + * 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.util.function.xconnect; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest; +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._static.rev180301.srv6._static.cfg.Sid; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndDX2FunctionBinder extends XConnectFunctionBinder { + + public EndDX2FunctionBinder(@Nonnull final FutureJVppCore api, @Nonnull final NamingContext interfaceContext) { + super(api, interfaceContext); + } + + @Nonnull + @Override + public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, + @Nonnull WriteContext ctx) { + Preconditions.checkNotNull(data.getEndDx2(), "EndDx2 data cannot be null."); + Preconditions.checkNotNull(data.getEndDx2().getPaths(), "EndDx2 paths cannot be null."); + Preconditions.checkNotNull(data.getEndDx2().getPaths().getInterface(), "EndDx2 Interface cannot be null."); + XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp()); + String outInterface = data.getEndDx2().getPaths().getInterface(); + Preconditions.checkArgument(outInterface != null && !outInterface.isEmpty(), + "Failed to map data: {} for request: {}", data, request); + request.setOutgoingInterfaceIndex(getInterfaceIndex(ctx.getMappingContext(), outInterface)); + request.setFunction(getBehaviourFunctionType()); + return request; + } + + @Nonnull + @Override + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return EndDX2.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java new file mode 100644 index 000000000..51abc9876 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX4FunctionBinder.java @@ -0,0 +1,60 @@ +/* + * 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.util.function.xconnect; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v4.paths.Path; +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.types.rev180301.EndDX4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndDX4FunctionBinder extends XConnectFunctionBinder { + + public EndDX4FunctionBinder(@Nonnull FutureJVppCore api, @Nonnull NamingContext interfaceContext) { + super(api, interfaceContext); + } + + @Nonnull + @Override + public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, @Nonnull WriteContext ctx) { + XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp()); + Preconditions.checkNotNull(data.getEndDx4(), "EndDx4 data cannot be null."); + Preconditions.checkNotNull(data.getEndDx4().getPaths(), "EndDx4 paths cannot be null."); + Preconditions.checkNotNull(data.getEndDx4().getPaths().getPath(), "EndDx4 list of paths cannot be null."); + Optional<Path> firstPathOptional = data.getEndDx4().getPaths().getPath().stream().findFirst(); + Preconditions + .checkArgument(firstPathOptional.isPresent(), "Failed to map data: {} for request: {}", data, request); + request.setOutgoingInterfaceIndex( + getInterfaceIndex(ctx.getMappingContext(), firstPathOptional.get().getInterface())); + request.setNextHopAddress(new IpAddress(firstPathOptional.get().getNextHop())); + request.setFunction(getBehaviourFunctionType()); + return request; + } + + @Nonnull + @Override + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return EndDX4.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java new file mode 100644 index 000000000..71194fbd4 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndDX6FunctionBinder.java @@ -0,0 +1,60 @@ +/* + * 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.util.function.xconnect; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.Path; +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.types.rev180301.EndDX6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +public class EndDX6FunctionBinder extends XConnectFunctionBinder { + + public EndDX6FunctionBinder(@Nonnull FutureJVppCore api, @Nonnull NamingContext interfaceContext) { + super(api, interfaceContext); + } + + @Nonnull + @Override + public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, @Nonnull WriteContext ctx) { + XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp()); + Preconditions.checkNotNull(data.getEndDx6(), "EndDx6 data cannot be null."); + Preconditions.checkNotNull(data.getEndDx6().getPaths(), "EndDx6 paths cannot be null."); + Preconditions.checkNotNull(data.getEndDx6().getPaths().getPath(), "EndDx6 list of paths cannot be null."); + Optional<Path> firstPathOptional = data.getEndDx6().getPaths().getPath().stream().findFirst(); + Preconditions + .checkArgument(firstPathOptional.isPresent(), "Failed to map data: {} for request: {}", data, request); + request.setOutgoingInterfaceIndex( + getInterfaceIndex(ctx.getMappingContext(), firstPathOptional.get().getInterface())); + request.setNextHopAddress(new IpAddress(firstPathOptional.get().getNextHop())); + request.setFunction(getBehaviourFunctionType()); + return request; + } + + @Nonnull + @Override + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return EndDX6.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java new file mode 100644 index 000000000..0b3af395c --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/EndXFunctionBinder.java @@ -0,0 +1,61 @@ +/* + * 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.util.function.xconnect; + +import com.google.common.base.Preconditions; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Optional; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6._static.rev180301.multi.paths.v6.paths.Path; +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.types.rev180301.Srv6EndpointType; + +public class EndXFunctionBinder extends XConnectFunctionBinder { + + public EndXFunctionBinder(@Nonnull FutureJVppCore api, @Nonnull NamingContext interfaceContext) { + super(api, interfaceContext); + } + + @Nonnull + @Override + public XConnectLocalSidRequest createWriteRequestAndBind(@Nonnull Sid data, + @Nonnull WriteContext ctx) { + XConnectLocalSidRequest request = new XConnectLocalSidRequest(getFutureJVpp()); + Preconditions.checkNotNull(data.getEndX(), "EndX data cannot be null."); + Preconditions.checkNotNull(data.getEndX().getPaths(), "EndX paths cannot be null."); + Preconditions.checkNotNull(data.getEndX().getPaths().getPath(), "EndX list of paths cannot be null."); + Optional<Path> firstPathOptional = data.getEndX().getPaths().getPath().stream().findFirst(); + Preconditions + .checkArgument(firstPathOptional.isPresent(), "Failed to map data: {} for request: {}", data, request); + + request.setOutgoingInterfaceIndex( + getInterfaceIndex(ctx.getMappingContext(), firstPathOptional.get().getInterface())); + request.setNextHopAddress(new IpAddress(firstPathOptional.get().getNextHop())); + request.setFunction(getBehaviourFunctionType()); + return request; + } + + @Nonnull + @Override + public Class<? extends Srv6EndpointType> getHandledFunctionType() { + return org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX.class; + } +} diff --git a/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java new file mode 100644 index 000000000..9f69c9041 --- /dev/null +++ b/srv6/srv6-impl/src/main/java/io/fd/hc2vpp/srv6/util/function/xconnect/XConnectFunctionBinder.java @@ -0,0 +1,65 @@ +/* + * 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.util.function.xconnect; + +import static com.google.common.base.Preconditions.checkState; +import static java.lang.String.format; + +import com.google.common.collect.ImmutableMap; +import io.fd.hc2vpp.common.translate.util.AddressTranslator; +import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer; +import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.hc2vpp.srv6.util.function.LocalSidFunctionBinder; +import io.fd.hc2vpp.srv6.write.sid.request.XConnectLocalSidRequest; +import io.fd.honeycomb.translate.MappingContext; +import io.fd.vpp.jvpp.core.future.FutureJVppCore; +import java.util.Map; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX2; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndDX6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.EndX; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.srv6.types.rev180301.Srv6EndpointType; + +abstract class XConnectFunctionBinder extends FutureJVppCustomizer + implements LocalSidFunctionBinder<XConnectLocalSidRequest>, AddressTranslator { + + private static final Map<Class<? extends Srv6EndpointType>, Integer> + REGISTER = ImmutableMap.of(EndX.class, 2, + EndDX2.class, 5, + EndDX4.class, 7, + EndDX6.class, 6); + + private final NamingContext interfaceContext; + + XConnectFunctionBinder(@Nonnull final FutureJVppCore api, @Nonnull final NamingContext interfaceContext) { + super(api); + this.interfaceContext = interfaceContext; + checkState(REGISTER.containsKey(getHandledFunctionType()), "Unsupported type of Local SID function %s", + getHandledFunctionType()); + } + + @Override + public int getBehaviourFunctionType() { + return REGISTER.get(getHandledFunctionType()); + } + + int getInterfaceIndex(final MappingContext ctx, final String name) { + return interfaceContext.getIndex(name, ctx, () -> new IllegalArgumentException( + format("Interface with name %s not found", name))); + } +} |