Bump versions by 0.1.0 for next dev cycle
[vpnservice.git] / bgpmanager / bgpmanager-impl / src / main / java / org / opendaylight / bgpmanager / commands / Vrf.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.apache.karaf.shell.commands.*;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.bgpmanager.BgpManager;
14 import java.util.*;
15
16 @Command(scope = "odl", name = "bgp-vrf", 
17          description = "Add or delete BGP VRFs")
18 public class Vrf extends OsgiCommandSupport {
19     private static final String RD = "--rd";
20     private static final String IR = "--import-rts";
21     private static final String ER = "--export-rts";
22
23     @Argument(name="add|del", description="The desired operation", 
24               required=true, multiValued = false)
25     private String action = null;
26
27     @Option(name=RD, aliases={"-r"}, 
28             description="Route distinguisher", 
29             required=false, multiValued=false)
30     private String rd = null;
31
32     @Option(name=IR, aliases={"-i"},
33             description="Import route-targets", 
34             required=false, multiValued=true)
35     private List<String> irts = null;
36
37     @Option(name=ER, aliases={"-e"},
38             description="Export route-targets", 
39             required=false, multiValued=true)
40     private List<String> erts = null;
41
42     private Object usage() {
43         System.err.println(
44             "usage: bgp-vrf ["+RD+" rd] [<"+IR+" | "+ER+"> rt1] .. [<"+ 
45             IR+" | "+ER+"> rtN] <add|del>");
46         return null;
47     }       
48
49     @Override
50     protected Object doExecute() throws Exception {
51         if (!Commands.bgpRunning()) {
52             return null;
53         }
54         BgpManager bm = Commands.getBgpManager();
55         switch (action) {
56             case "add" : 
57                 if (rd == null || irts == null || erts == null) {
58                     System.err.println("error: all options needed");
59                     return null;
60                 }
61                 // check: rd exists? rd & rt's in format?
62                 bm.addVrf(rd, irts, erts);
63                 break;
64             case "del" :  
65                 if (rd == null) {
66                     System.err.println("error: "+RD+" needed");
67                     return null;
68                 }
69                 if (irts != null || erts != null) {
70                     System.err.println("error: some option(s) not needed; ignored");
71                 }
72                 // check: rd exists? in format?
73                 bm.deleteVrf(rd);
74                 break; 
75             default : 
76                 return usage();
77         }
78         return null;
79     }
80 }