2 * Copyright (c) 2015 Yale University 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
9 package org.opendaylight.alto.commons.types.converter;
11 import java.util.LinkedList;
13 import org.opendaylight.alto.commons.helper.Converter;
14 import org.opendaylight.alto.commons.types.model150404.ModelCostMap;
15 import org.opendaylight.alto.commons.types.model150404.ModelCostMapData;
16 import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
18 public class RFC2ModelCostMapConverter
19 extends Converter<RFC7285CostMap, ModelCostMap>{
21 protected RFC2ModelCostMapMetaConverter metaConv = new RFC2ModelCostMapMetaConverter();
22 protected RFC2ModelCostMapDataConverter dataConv = new RFC2ModelCostMapDataConverter();
24 public RFC2ModelCostMapConverter() {
27 public RFC2ModelCostMapConverter(RFC7285CostMap _in) {
32 protected Object _convert() {
33 ModelCostMap out = new ModelCostMap();
34 out.rid = getCostMapResourceId(in());
35 //TODO: replace the dummy one in the future
36 out.tag = "da65eca2eb7a10ce8b059740b0b2e3f8eb1d4786";
38 out.meta = metaConv.convert(in().meta);
39 out.map = new LinkedList<ModelCostMapData>();
40 for (String src : in().map.keySet()) {
41 ModelCostMapData data = new ModelCostMapData();
43 data.dstCosts = dataConv.convert(in().map.get(src));
49 private String getCostMapResourceId(RFC7285CostMap costMap) {
50 String networkMapRID = costMap.meta.netmap_tags.get(0).rid;
51 String costMetric = costMap.meta.costType.metric;
52 String costMode = costMap.meta.costType.mode;
53 return networkMapRID + "-" + costMetric + "-" + costMode;