29e0c9ae82c8568e5b64f8c1e0d586f38f0a3c66
[bgpcep.git] / pcep / pcc-mock / src / main / java / org / opendaylight / protocol / pcep / pcc / mock / PCCTunnelBuilder.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  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
9 package org.opendaylight.protocol.pcep.pcc.mock;
10
11 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
12
13 import com.google.common.collect.Lists;
14 import java.util.HashMap;
15 import java.util.Map;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.protocol.pcep.pcc.mock.api.LspType;
18 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.PlspId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
26
27 final class PCCTunnelBuilder {
28     private static final Subobject DEFAULT_ENDPOINT_HOP = getDefaultEROEndpointHop();
29     private static final String ENDPOINT_ADDRESS = "1.1.1.1";
30     private static final String ENDPOINT_PREFIX = ENDPOINT_ADDRESS + "/32";
31     static final int PCC_DELEGATION = -1;
32
33     private PCCTunnelBuilder() {
34         throw new UnsupportedOperationException();
35     }
36
37     @Nonnull
38     static Map<PlspId, PCCTunnel> createTunnels(final String address, final int lsps) {
39         final Map<PlspId, PCCTunnel> tunnels = new HashMap<>();
40         for (int i = 1; i <= lsps; i++) {
41             final PCCTunnel tunnel = new PCCTunnel(MsgBuilderUtil.getDefaultPathName(address, i),
42                     PCC_DELEGATION, LspType.PCC_LSP, createPath(Lists.newArrayList(DEFAULT_ENDPOINT_HOP)));
43             tunnels.put(new PlspId((long) i), tunnel);
44         }
45         return tunnels;
46     }
47
48     private static Subobject getDefaultEROEndpointHop() {
49         final SubobjectBuilder builder = new SubobjectBuilder();
50         builder.setLoose(false);
51         builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(
52             new IpPrefix(new Ipv4Prefix(ENDPOINT_PREFIX))).build()).build());
53         return builder.build();
54     }
55 }