Merge "Ganymed patch fix"
[controller.git] / opendaylight / md-sal / sal-compability / src / main / java / org / opendaylight / controller / sal / compability / ToSalPropertyClassUtils.java
1 package org.opendaylight.controller.sal.compability;
2
3 import org.opendaylight.controller.sal.core.*;
4 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
7
8 public class ToSalPropertyClassUtils {
9     public static Bandwidth salAdvertisedBandwidthFrom(NodeConnector nodeConnector) {
10         FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
11         PortFeatures portFeatures = flowCapNodeConn.getAdvertisedFeatures();
12         return new AdvertisedBandwidth(resolveBandwidth(portFeatures));
13     }
14
15     public static Bandwidth salPeerBandwidthFrom(NodeConnector nodeConnector) {
16         FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
17         PortFeatures portFeatures = flowCapNodeConn.getPeerFeatures();
18         return new PeerBandwidth(resolveBandwidth(portFeatures));
19     }
20
21     public static Bandwidth salSupportedBandwidthFrom(NodeConnector nodeConnector) {
22         FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
23         PortFeatures portFeatures = flowCapNodeConn.getSupported();
24         return new SupportedBandwidth(resolveBandwidth(portFeatures));
25     }
26
27     public static MacAddress salMacAddressFrom(NodeConnector nodeConnector) {
28         FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
29         String hwAddress = flowCapNodeConn.getHardwareAddress().getValue();
30         return new MacAddress(bytesFrom(hwAddress));        
31     }
32     
33     
34     public static Name salNameFrom(NodeConnector nodeConnector) {
35         FlowCapableNodeConnector flowCapNodeConn = nodeConnector.getAugmentation(FlowCapableNodeConnector.class);        
36         return new Name(flowCapNodeConn.getName());
37     }
38     
39     
40
41     private static byte[] bytesFrom(String hwAddress) {
42         String[] mac = hwAddress.split(":");
43         byte[] macAddress = new byte[6]; // mac.length == 6 bytes
44         for (int i = 0; i < mac.length; i++) {
45             macAddress[i] = Integer.decode("0x" + mac[i]).byteValue();
46         }
47         return macAddress;
48     }
49
50     private static long resolveBandwidth(PortFeatures portFeatures) {
51         if (portFeatures.is_1tbFd()) {
52             return Bandwidth.BW1Tbps;
53         } else if (portFeatures.is_100gbFd()) {
54             return Bandwidth.BW100Gbps;
55         } else if (portFeatures.is_40gbFd()) {
56             return Bandwidth.BW40Gbps;
57         } else if (portFeatures.is_10gbFd()) {
58             return Bandwidth.BW10Gbps;
59         } else if (portFeatures.is_1gbHd() || portFeatures.is_1gbFd()) {
60             return Bandwidth.BW1Gbps;
61         } else if (portFeatures.is_100mbHd() || portFeatures.is_100mbFd()) {
62             return Bandwidth.BW100Mbps;
63         } else if (portFeatures.is_10mbHd() || portFeatures.is_10mbFd()) {
64             return Bandwidth.BW10Mbps;
65         } else {
66             return Bandwidth.BWUNK;
67         }
68     }
69
70 }