Add INFO.yaml for GBP
[groupbasedpolicy.git] / neutron-vpp-mapper / src / main / java / org / opendaylight / groupbasedpolicy / neutron / vpp / mapper / util / HandlerUtil.java
1 /*
2  * Copyright (c) 2017 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.groupbasedpolicy.neutron.vpp.mapper.util;
10
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.Config;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnetBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnetKey;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.gbp.subnet.base.attributes.AllocationPools;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.gbp.subnet.base.attributes.AllocationPoolsBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.gbp.subnet.base.attributes.AllocationPoolsKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20
21 import java.util.stream.Collectors;
22
23 /**
24  * Created by Shakib Ahmed on 4/25/17.
25  */
26 public class HandlerUtil {
27     public static GbpSubnet toGbpSubnet(Subnet subnet) {
28         GbpSubnetBuilder gbpSubnetBuilder = new GbpSubnetBuilder();
29         gbpSubnetBuilder.setKey(new GbpSubnetKey(subnet.getUuid().getValue()));
30         gbpSubnetBuilder.setId(subnet.getUuid().getValue());
31         gbpSubnetBuilder.setCidr(subnet.getCidr());
32         gbpSubnetBuilder.setGatewayIp(subnet.getGatewayIp());
33         gbpSubnetBuilder.setAllocationPools(subnet.getAllocationPools()
34                                                 .stream()
35                                                 .map(allocationPools -> toGbpAllocationPools(allocationPools))
36                                                 .collect(Collectors.toList()));
37         return gbpSubnetBuilder.build();
38     }
39
40     private static AllocationPools toGbpAllocationPools(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.
41                                                         subnet.attributes.AllocationPools pool) {
42         AllocationPoolsBuilder allocationPoolsBuilder = new AllocationPoolsBuilder();
43         allocationPoolsBuilder.setKey(new AllocationPoolsKey(pool.getStart()));
44         allocationPoolsBuilder.setStart(pool.getStart());
45         allocationPoolsBuilder.setEnd(pool.getEnd());
46         return allocationPoolsBuilder.build();
47     }
48
49     public static InstanceIdentifier<GbpSubnet> getInstanceIdentifier(String subnetUuid) {
50         return InstanceIdentifier
51                 .builder(Config.class)
52                 .child(GbpSubnet.class, new GbpSubnetKey(subnetUuid)).build();
53     }
54 }