Add INFO.yaml for nemo
[nemo.git] / nemo-renderers / openflow-renderer / src / main / java / org / opendaylight / nemo / renderer / openflow / physicalnetwork / Utils.java
1 /*
2  * Copyright (c) 2015 Huawei, 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.nemo.renderer.openflow.physicalnetwork;
10
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNodeInstance;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalPortInstance;
13
14 import java.io.BufferedReader;
15 import java.io.FileInputStream;
16 import java.io.IOException;
17 import java.io.InputStreamReader;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 /**
21  * Created by hj on 11/5/15.
22  */
23 public class Utils {
24     private static final Logger log = LoggerFactory.getLogger(Utils.class);
25     protected static PhysicalNodeInstance.NodeType getNodeType(String strType){
26         switch (strType){
27             case "switch":
28                 return PhysicalNodeInstance.NodeType.Switch;
29             case "router":
30                 return PhysicalNodeInstance.NodeType.Router;
31             case "firewall":
32                 return PhysicalNodeInstance.NodeType.Firewall;
33             case "loadbalancer":
34                 return PhysicalNodeInstance.NodeType.Loadbalancer;
35         }
36         return null;
37     }
38     protected static PhysicalPortInstance.PortType getPortType(String strType){
39         switch (strType){
40             case "external":
41                 return PhysicalPortInstance.PortType.External;
42         }
43         return PhysicalPortInstance.PortType.Internal;
44     }
45     protected static String readFile(String Path){
46         BufferedReader reader = null;
47         String laststr = "";
48         try{
49             FileInputStream fileInputStream = new FileInputStream(Path);
50             InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
51             reader = new BufferedReader(inputStreamReader);
52             String tempString = null;
53             while((tempString = reader.readLine()) != null){
54                 laststr += tempString;
55             }
56             reader.close();
57         }catch(IOException e){
58             // TODO Auto-generated catch block
59             log.error("Exception:",e);
60         }finally{
61             if(reader != null){
62                 try {
63                     reader.close();
64                 } catch (IOException e) {
65                     // TODO Auto-generated catch block
66                     log.error("Exception:",e);
67                 }
68             }
69         }
70         return laststr;
71     }
72
73 }