UNREACH-DESTINATION Object
[bgpcep.git] / pcep / base-parser / src / main / java / org / opendaylight / protocol / pcep / parser / object / unreach / PCEPUnreachDestinationSerializer.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.parser.object.unreach;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase;
18
19 public final class PCEPUnreachDestinationSerializer implements ObjectSerializer {
20     @Override
21     public void serializeObject(final Object object, final ByteBuf buffer) {
22         Preconditions.checkArgument(object instanceof UnreachDestinationObj,
23             "Wrong instance of PCEPObject. Passed %s. Needed UnreachDestinationObj.", object.getClass());
24         final UnreachDestinationObj uPObj = (UnreachDestinationObj) object;
25         final Destination destination = uPObj.getDestination();
26         final Boolean processing = object.isProcessingRule();
27         final Boolean ignore = object.isIgnore();
28         if (destination instanceof Ipv6DestinationCase) {
29             final Ipv6DestinationCase ipv6 = ((Ipv6DestinationCase) destination);
30             PCEPIpv6UnreachDestinationParser.serializeObject(processing, ignore, ipv6, buffer);
31         } else if (destination instanceof Ipv4DestinationCase) {
32             final Ipv4DestinationCase ipv4 = ((Ipv4DestinationCase) destination);
33             PCEPIpv4UnreachDestinationParser.serializeObject(processing, ignore, ipv4, buffer);
34         }
35     }
36 }