2 * Copyright (c) 2018 AT&T Intellectual Property. 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.pcep.parser.object.bnc;
10 import com.google.common.base.Preconditions;
11 import java.util.List;
12 import java.util.stream.Collectors;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.Subobject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.SubobjectBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
20 public final class BNCUtil {
25 public static List<Subobject> toBncSubobject(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
26 .ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject> subobject) {
27 return subobject.stream()
29 final SubobjectType type = sob.getSubobjectType();
30 Preconditions.checkArgument(type instanceof IpPrefixCase,
31 "Wrong instance of PCEPObject. Passed %s. Needed IpPrefixCase.", type.getClass());
32 return new SubobjectBuilder().setIpPrefix(((IpPrefixCase) type).getIpPrefix().getIpPrefix())
33 .setLoose(sob.getLoose()).build();
34 }).collect(Collectors.toList());
37 public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
38 .route.object.ero.Subobject> toIroSubject(final List<Subobject> subobject) {
39 return subobject.stream()
41 final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit
42 .route.subobjects.subobject.type.ip.prefix._case.IpPrefix prefix = new IpPrefixBuilder()
43 .setIpPrefix(sob.getIpPrefix()).build();
44 final IpPrefixCase subObjType = new IpPrefixCaseBuilder().setIpPrefix(prefix).build();
45 return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
46 .explicit.route.object.ero.SubobjectBuilder()
47 .setSubobjectType(subObjType)
48 .setLoose(sob.getLoose())
50 }).collect(Collectors.toList());