2 * Copyright © 2015 ZTE and others. 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 com.highstreet.technologies.odl.app.impl;
10 import com.highstreet.technologies.odl.app.impl.delegates.FC;
11 import com.highstreet.technologies.odl.app.impl.delegates.PredefinePath;
12 import com.highstreet.technologies.odl.app.impl.tools.FC2Executor;
13 import com.highstreet.technologies.odl.app.impl.tools.JsonUtil;
14 import com.highstreet.technologies.odl.app.impl.tools.MountPointServiceHolder;
15 import com.highstreet.technologies.odl.app.impl.tools.NeExecutor;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceConfiguration;
19 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceStatus;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.route.rev150105.*;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.route.rev150105.fc_desc.Fc;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.concurrent.Future;
33 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
34 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
35 import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.route.rev150105.StatusG.Status;
36 import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.route.rev150105.StatusG.Status.Successful;
39 * Created by olinchy on 5/22/17.
41 public class RouteRPC implements RouteService
43 public RouteRPC(DataBroker dataBroker)
45 this.dataBroker = dataBroker;
46 fc2Executor = new FC2Executor();
49 private static final Logger LOG = LoggerFactory.getLogger(RouteRPC.class);
50 public static HashMap<String, NeExecutor> ne_map = new HashMap<>();
51 private static HashMap<Integer, PathHolder> toClear = new HashMap<>();
52 private static PredefinePath predefinePath;
56 predefinePath = JsonUtil.toObject(
57 RouteRPC.class.getClassLoader().getResource("topology.json"), PredefinePath.class);
60 private final DataBroker dataBroker;
61 private FC2Executor fc2Executor;
64 public Future<RpcResult<Void>> readAirInterface(
65 ReadAirInterfaceInput input)
67 String lpName = input.getLpId();
68 String nodeName = input.getNodeName();
69 NeExecutor executor = ne_map.computeIfAbsent(
70 nodeName, n -> new NeExecutor(MountPointServiceHolder.getMountPoint(n)));
73 AirInterfaceConfiguration airInterfaceConfiguration = executor.getUnderAirPac(
74 lpName, AirInterfaceConfiguration.class, CONFIGURATION);
75 AirInterfaceStatus airInterfaceStatus = executor.getUnderAirPac(
76 lpName, AirInterfaceStatus.class, OPERATIONAL);
77 LOG.info(airInterfaceConfiguration.toString());
78 LOG.info(airInterfaceStatus != null ? airInterfaceStatus.toString() : "airInterfaceStatus is null");
89 public Future<RpcResult<RestoreFollowTopoOutput>> restoreFollowTopo(
90 RestoreFollowTopoInput input)
92 RestoreFollowTopoOutputBuilder builder = new RestoreFollowTopoOutputBuilder();
93 builder.setStatus(switchTo(
95 Arrays.asList(predefinePath.paths.get(String.valueOf(input.getVlanid())).main_ltps)));
96 return RpcResultBuilder.success(builder.build()).buildFuture();
100 public Future<RpcResult<CreateFollowTopoOutput>> createFollowTopo(
101 CreateFollowTopoInput input)
103 CreateFollowTopoOutputBuilder builder = new CreateFollowTopoOutputBuilder();
104 int vlanId = input.getVlanid();
105 ArrayList<Fc> listFc = new ArrayList<>();
106 Arrays.stream(predefinePath.paths.get(String.valueOf(vlanId)).main_ltps).forEach(fc -> listFc.add(fc.toFc()));
108 builder.setStatus(this.create(vlanId, listFc));
109 LOG.info("creation follow the topology finished");
110 return RpcResultBuilder.success(builder.build()).buildFuture();
114 public Future<RpcResult<SwitchFollowTopoOutput>> switchFollowTopo(
115 SwitchFollowTopoInput input)
117 SwitchFollowTopoOutputBuilder builder = new SwitchFollowTopoOutputBuilder();
121 Arrays.asList(predefinePath.paths.get(String.valueOf(input.getVlanid())).backup_ltps)));
122 LOG.info("switch follow the topology finished");
123 return RpcResultBuilder.success(builder.build()).buildFuture();
127 public Future<RpcResult<DeleteOutput>> delete(
130 DeleteOutputBuilder builder = new DeleteOutputBuilder();
131 builder.setStatus(this.delete(input.getVlanid()));
132 LOG.info("delete finished");
133 return RpcResultBuilder.success(builder.build()).buildFuture();
137 public Future<RpcResult<CreateOutput>> create(
140 CreateOutputBuilder builder = new CreateOutputBuilder();
141 builder.setStatus(this.create(input.getVlanid(), input.getFc()));
142 return RpcResultBuilder.success(builder.build()).buildFuture();
145 private Status switchTo(int vlanId, List<FC> list)
148 ArrayList<Fc> listFc = new ArrayList<>();
150 fc -> listFc.add(fc.toFc()));
151 return this.create(vlanId, listFc);
154 public Status delete(int vlanId)
158 toClear.remove(vlanId).clear(vlanId);
162 LOG.warn("execute delete caught exception", e);
168 private Status create(int vlanId, List<Fc> fcList)
170 PathHolder pathHolder = new PathHolder(dataBroker, vlanId);
178 pathHolder.add(fc2Executor.to(fc, vlanId, pathHolder.getLtpCreator()));
180 catch (ReadFailedException e)
182 LOG.warn("read failed", e);
189 LOG.warn("creating LtpPath caught exception", e);
191 toClear.put(vlanId, pathHolder);