2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.bgp.flowspec;
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeParser;
15 import org.opendaylight.protocol.bgp.flowspec.handlers.FlowspecTypeSerializer;
16 import org.opendaylight.protocol.bgp.flowspec.handlers.NumericOneByteOperandParser;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.NumericOperand;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.flowspec.FlowspecType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.NextHeaderCaseBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.next.header._case.NextHeaders;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev180329.flowspec.destination.group.ipv6.flowspec.flowspec.type.next.header._case.NextHeadersBuilder;
24 public final class FSIpv6NextHeaderHandler implements FlowspecTypeParser, FlowspecTypeSerializer {
25 public static final int NEXT_HEADER_VALUE = 3;
28 public void serializeType(FlowspecType value, ByteBuf output) {
29 Preconditions.checkArgument(value instanceof NextHeaderCase, "NextHeaderCase class is mandatory!");
30 output.writeByte(NEXT_HEADER_VALUE);
31 NumericOneByteOperandParser.INSTANCE.serialize(((NextHeaderCase) value).getNextHeaders(), output);
35 public FlowspecType parseType(ByteBuf buffer) {
39 return new NextHeaderCaseBuilder().setNextHeaders(parseNextHeader(buffer)).build();
42 private static List<NextHeaders> parseNextHeader(final ByteBuf nlri) {
43 final List<NextHeaders> headers = new ArrayList<>();
45 // we can do this as all fields will be rewritten in the cycle
46 final NextHeadersBuilder builder = new NextHeadersBuilder();
48 final byte b = nlri.readByte();
49 final NumericOperand op = NumericOneByteOperandParser.INSTANCE.parse(b);
51 builder.setValue(nlri.readUnsignedByte());
52 end = op.isEndOfList();
53 headers.add(builder.build());