Refactoring of cisco-xr-driver and impl modules.
[unimgr.git] / cisco-xr-driver / src / main / java / org / opendaylight / unimgr / mef / nrp / cisco / xr / l2vpn / activator / L2vpnXconnectActivator.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.unimgr.mef.nrp.cisco.xr.l2vpn.activator;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
12 import org.opendaylight.unimgr.mef.nrp.cisco.xr.common.helper.BandwidthProfileHelper;
13 import org.opendaylight.unimgr.mef.nrp.cisco.xr.common.helper.InterfaceHelper;
14 import org.opendaylight.unimgr.mef.nrp.cisco.xr.common.util.LoopbackUtils;
15 import org.opendaylight.unimgr.mef.nrp.cisco.xr.common.util.MtuUtils;
16 import org.opendaylight.unimgr.mef.nrp.cisco.xr.l2vpn.helper.AttachmentCircuitHelper;
17 import org.opendaylight.unimgr.mef.nrp.cisco.xr.l2vpn.helper.L2vpnHelper;
18 import org.opendaylight.unimgr.mef.nrp.cisco.xr.l2vpn.helper.PseudowireHelper;
19 import org.opendaylight.unimgr.mef.nrp.cisco.xr.l2vpn.helper.XConnectHelper;
20 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.asr9k.policymgr.cfg.rev150518.PolicyManager;
21 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.ifmgr.cfg.rev150730.InterfaceConfigurations;
22 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.ifmgr.cfg.rev150730._interface.configurations._interface.configuration.Mtus;
23 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.l2vpn.cfg.rev151109.L2vpn;
24 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.l2vpn.cfg.rev151109.l2vpn.database.XconnectGroups;
25 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.l2vpn.cfg.rev151109.l2vpn.database.xconnect.groups.XconnectGroup;
26 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.l2vpn.cfg.rev151109.l2vpn.database.xconnect.groups.xconnect.group.p2p.xconnects.p2p.xconnect.AttachmentCircuits;
27 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.l2vpn.cfg.rev151109.l2vpn.database.xconnect.groups.xconnect.group.p2p.xconnects.p2p.xconnect.Pseudowires;
28 import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.xr.types.rev150629.CiscoIosXrString;
29 import org.opendaylight.yang.gen.v1.urn.onf.core.network.module.rev160630.g_forwardingconstruct.FcPort;
30
31 import java.util.Optional;
32
33 import static org.opendaylight.unimgr.mef.nrp.cisco.xr.common.helper.BandwidthProfileComposition.BwpApplicability.UNI;
34 import static org.opendaylight.unimgr.mef.nrp.cisco.xr.common.helper.BandwidthProfileComposition.BwpDirection.EGRESS;
35 import static org.opendaylight.unimgr.mef.nrp.cisco.xr.common.helper.BandwidthProfileComposition.BwpDirection.INGRESS;
36
37
38 /**
39  * Activator of VPLS-based L2 VPN using cross connect connection on IOS-XR devices
40  *
41  * @author krzysztof.bijakowski@amartus.com
42  */
43 public class L2vpnXconnectActivator extends AbstractL2vpnActivator {
44
45     public L2vpnXconnectActivator(DataBroker dataBroker, MountPointService mountService) {
46         super(dataBroker, mountService);
47     }
48
49     @Override
50     protected Optional<PolicyManager> activateQos(String name, FcPort port) {
51         return new BandwidthProfileHelper(dataBroker, port)
52                 .addPolicyMap(name, INGRESS, UNI)
53                 .addPolicyMap(name, EGRESS, UNI)
54                 .build();
55     }
56
57     @Override
58     public InterfaceConfigurations activateInterface(FcPort port, FcPort neighbor, long mtu) {
59         Mtus mtus = new MtuUtils().generateMtus(mtu, new CiscoIosXrString("GigabitEthernet"));
60
61         return new InterfaceHelper()
62             .addInterface(port, Optional.of(mtus), true)
63             .build();
64     }
65
66     @Override
67     public Pseudowires activatePseudowire(FcPort neighbor) {
68         return new PseudowireHelper()
69              .addPseudowire(LoopbackUtils.getIpv4Address(neighbor, dataBroker))
70              .build();
71     }
72
73     @Override
74     public XconnectGroups activateXConnect(String outerName, String innerName, FcPort port, FcPort neighbor, Pseudowires pseudowires) {
75         AttachmentCircuits attachmentCircuits = new AttachmentCircuitHelper()
76              .addPort(port)
77              .build();
78
79         XconnectGroup xconnectGroup = new XConnectHelper()
80              .appendXConnect(innerName, attachmentCircuits, pseudowires)
81              .build(outerName);
82
83         return XConnectHelper.createXConnectGroups(xconnectGroup);
84     }
85
86     @Override
87     public L2vpn activateL2Vpn(XconnectGroups xconnectGroups) {
88         return L2vpnHelper.build(xconnectGroups);
89     }
90 }