2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.netvirt.bgpmanager.commands;
11 import java.util.List;
12 import org.apache.karaf.shell.commands.Argument;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.OsgiCommandSupport;
16 import org.opendaylight.netvirt.bgpmanager.BgpManager;
17 import org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.AddressFamily;
19 @Command(scope = "odl", name = "bgp-vrf",
20 description = "Add or delete BGP VRFs")
21 public class Vrf extends OsgiCommandSupport {
22 private static final String RD = "--rd";
23 private static final String IR = "--import-rts";
24 private static final String ER = "--export-rts";
25 private static final String ADDRF = "--addr-family";
27 @Argument(name = "add|del", description = "The desired operation",
28 required = true, multiValued = false)
29 private final String action = null;
31 @Option(name = RD, aliases = {"-r"},
32 description = "Route distinguisher",
33 required = false, multiValued = false)
34 private final String rd = null;
36 @Option(name = IR, aliases = {"-i"},
37 description = "Import route-targets",
38 required = false, multiValued = true)
39 private final List<String> irts = null;
41 @Option(name = ER, aliases = {"-e"},
42 description = "Export route-targets",
43 required = false, multiValued = true)
44 private final List<String> erts = null;
47 @Option(name = ADDRF, aliases = {"-af"},
48 description = "AddressFamily IPV4 or IPV6 or L2VPN (IPv(4 or 6) is on MPLS, L2VPN uses IPV4)",
49 required = false, multiValued = false)
50 private final String addrf = null;
52 private final BgpManager bgpManager;
54 public Vrf(BgpManager bgpManager) {
55 this.bgpManager = bgpManager;
58 private Object usage() {
59 session.getConsole().println(
60 "usage: bgp-vrf [" + RD + " rd] [<" + IR + " | " + ER + "> rt1] .. [<" + IR + " | " + ER
61 + "> rtN] [" + ADDRF + " AddressFamily] <add|del>");
66 protected Object doExecute() throws Exception {
67 AddressFamily af = null;
68 if (addrf.compareToIgnoreCase("IPV_4") == 0) {
69 af = AddressFamily.IPV4;
70 } else if (addrf.compareToIgnoreCase("IPV_6") == 0) {
71 af = AddressFamily.IPV6;
72 } else if (addrf.compareToIgnoreCase("L2VPN") == 0) {
73 af = AddressFamily.L2VPN;
79 if (rd == null || irts == null || erts == null) {
80 session.getConsole().println("error: all options needed");
83 // check: rd exists? rd & rt's in format?
84 bgpManager.addVrf(rd, irts, erts, af);
88 session.getConsole().println("error: " + RD + " needed");
91 if (irts != null || erts != null) {
92 session.getConsole().println("error: some option(s) not needed; ignored");
94 // check: rd exists? in format?
95 bgpManager.deleteVrf(rd, true, af);