Merge "Upgrade ietf-{inet,yang}-types to 2013-07-15"
[vpnservice.git] / bgpmanager / bgpmanager-impl / src / main / java / org / opendaylight / bgpmanager / commands / Commands.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.bgpmanager.commands;
10
11 import org.opendaylight.bgpmanager.BgpManager;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.*;
13
14 public class Commands {
15     private static BgpManager bm;
16     public static final int IPADDR = 1;
17     public static final int INT = 2;
18
19     public Commands(BgpManager bgpm) {
20         bm = bgpm;
21     }
22
23     public static BgpManager getBgpManager() {
24         return bm;
25     }
26
27     public static boolean isValid(String val, int type, String name) {
28         switch (type) {
29             case INT : 
30                 try {
31                     int i = Integer.parseInt(val);
32                 } catch (NumberFormatException nme) {
33                     System.err.println("error: value of "+name+" is not an integer");
34                     return false;
35                 }
36                 break;
37             case IPADDR:
38                 try {
39                     Ipv4Address addr = new Ipv4Address(val);
40                 } catch (Exception e) {
41                     System.err.println("error: value of "+name+" is not an IP address");
42                     return false;
43                 }
44                 break;
45             default:
46                 return false;
47         }
48         return true;
49     }
50
51     public static boolean bgpRunning() {
52         if (getBgpManager() == null) {
53             System.err.println("error: cannot run command, BgpManager not started");
54             return false;
55         }
56         return true;
57     }
58 }
59