BUG-2218: Keep existing link augmentations during discovery process
[controller.git] / opendaylight / protocol_plugins / openflow / src / main / java / org / opendaylight / controller / protocol_plugin / openflow / internal / DescStatisticsConverter.java
1 /*
2  * Copyright (c) 2013 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.controller.protocol_plugin.openflow.internal;
10
11 import java.util.List;
12
13 import org.opendaylight.controller.sal.reader.NodeDescription;
14 import org.openflow.protocol.statistics.OFDescriptionStatistics;
15 import org.openflow.protocol.statistics.OFStatistics;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Utility class for converting openflow description statistics into SAL
21  * NodeDescription object
22  */
23 public class DescStatisticsConverter {
24     private static final Logger log = LoggerFactory
25             .getLogger(DescStatisticsConverter.class);
26     NodeDescription hwDesc;
27     OFDescriptionStatistics ofDesc;
28
29     public DescStatisticsConverter(List<OFStatistics> statsList) {
30         this.hwDesc = null;
31         this.ofDesc = (statsList == null || statsList.isEmpty())?
32                 null : (OFDescriptionStatistics) statsList.get(0);
33     }
34     public DescStatisticsConverter(OFDescriptionStatistics desc) {
35         this.hwDesc = null;
36         this.ofDesc = desc;
37     }
38
39     public NodeDescription getHwDescription() {
40         if (hwDesc == null && ofDesc != null) {
41             hwDesc = new NodeDescription();
42             hwDesc.setManufacturer(ofDesc.getManufacturerDescription());
43             hwDesc.setHardware(ofDesc.getHardwareDescription());
44             hwDesc.setSoftware(ofDesc.getSoftwareDescription());
45             hwDesc.setDescription(ofDesc.getDatapathDescription());
46             hwDesc.setSerialNumber(ofDesc.getSerialNumber());
47         }
48         log.trace("OFDescriptionStatistics: {}", ofDesc);
49         log.trace("NodeDescription: {}", hwDesc);
50         return hwDesc;
51     }
52
53 }