use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.TcpMd5SignaturePasswordType in project netvirt by opendaylight.
the class BgpConfigurationManager method addNeighbor.
public void addNeighbor(String nbrIp, long remoteAs, @Nullable final TcpMd5SignaturePasswordType md5Secret) {
Ipv4Address nbrAddr = new Ipv4Address(nbrIp);
InstanceIdentifier.InstanceIdentifierBuilder<Neighbors> iib = InstanceIdentifier.builder(Bgp.class).child(Neighbors.class, new NeighborsKey(nbrAddr));
InstanceIdentifier<Neighbors> iid = iib.build();
TcpSecurityOption tcpSecOption = null;
if (md5Secret != null) {
tcpSecOption = new TcpMd5SignatureOptionBuilder().setTcpMd5SignaturePassword(md5Secret).build();
}
// else let tcpSecOption be null
Neighbors dto = new NeighborsBuilder().setAddress(nbrAddr).setRemoteAs(remoteAs).setTcpSecurityOption(tcpSecOption).build();
update(iid, dto);
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.TcpMd5SignaturePasswordType in project netvirt by opendaylight.
the class ConfigureBgpCli method addNeighbor.
protected void addNeighbor() {
if (!validateAsNumber(asNumber)) {
printAddNeighborHelp();
return;
}
boolean validIp = validateIp(ip);
if (!validIp) {
session.getConsole().println("invalid neighbor ip");
printAddNeighborHelp();
return;
}
TcpMd5SignaturePasswordType md5secret = null;
if (md5passwordOption != null) {
try {
md5secret = new TcpMd5SignaturePasswordType(md5passwordOption);
} catch (IllegalArgumentException e) {
session.getConsole().println(new StringBuilder("invalid MD5 password: ").append(e.getMessage()).toString());
printAddNeighborHelp();
return;
}
}
if (sourceIp != null) {
validIp = validateIp(sourceIp);
if (!validIp) {
session.getConsole().println("invalid source ip");
printAddNeighborHelp();
return;
}
}
if (ebgpMultihops != null) {
try {
long val = Long.parseLong(ebgpMultihops);
if (val < 1 || val > 255) {
session.getConsole().println("invalid ebgpMultihops number , valid range [1,255] ");
printAddNeighborHelp();
return;
}
} catch (NumberFormatException e) {
session.getConsole().println("invalid ebgpMultihops number, valid range [1-255]");
printAddNeighborHelp();
return;
}
}
if (addressFamily != null) {
try {
af_safi.valueOf(addressFamily);
} catch (IllegalArgumentException e) {
session.getConsole().println("invalid addressFamily valid values SAFI_IPV4_LABELED_UNICAST | SAFI_MPLS_VPN");
printAddNeighborHelp();
return;
}
}
if (getAsNumber(ip) != -1) {
session.getConsole().println("neighbor with ip " + ip + " already exists");
return;
}
bgpManager.addNeighbor(ip, Long.parseLong(asNumber), md5secret);
if (addressFamily != null) {
bgpManager.addAddressFamily(ip, af_afi.AFI_IP, af_safi.valueOf(addressFamily));
}
if (ebgpMultihops != null) {
bgpManager.addEbgpMultihop(ip, Integer.parseInt(ebgpMultihops));
}
if (sourceIp != null) {
bgpManager.addUpdateSource(ip, sourceIp);
}
}
use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.TcpMd5SignaturePasswordType in project netvirt by opendaylight.
the class Neighbor method doExecute.
@Override
protected Object doExecute() {
switch(action) {
case "add":
if (nbrIp == null) {
session.getConsole().println("error: " + IP + " needed");
return null;
}
if (bgpManager.getConfig() == null) {
session.getConsole().println("error: Bgp config is not present");
return null;
}
long asn = 0;
int hops = 0;
if (!Commands.isValid(session.getConsole(), nbrIp, Commands.Validators.IPADDR, IP)) {
return null;
}
if (asNum != null) {
if (!Commands.isValid(session.getConsole(), asNum, Commands.Validators.INT, AS)) {
return null;
} else {
asn = Long.parseLong(asNum);
}
}
TcpMd5SignaturePasswordType md5Secret = null;
if (md5PasswordOption != null) {
try {
md5Secret = new TcpMd5SignaturePasswordType(md5PasswordOption);
} catch (IllegalArgumentException e) {
session.getConsole().println(new StringBuilder("error: invalid MD5 password ").append(e.getMessage()).toString());
return null;
}
}
bgpManager.addNeighbor(nbrIp, asn, md5Secret);
if (multiHops != null) {
if (!Commands.isValid(session.getConsole(), multiHops, Commands.Validators.INT, MH)) {
return null;
} else {
hops = Integer.parseInt(multiHops);
}
bgpManager.addEbgpMultihop(nbrIp, hops);
}
if (srcIp != null) {
if (!Commands.isValid(session.getConsole(), srcIp, Commands.Validators.IPADDR, US)) {
return null;
}
bgpManager.addUpdateSource(nbrIp, srcIp);
}
if (addrFamily != null) {
if (!addrFamily.equals("lu") && !addrFamily.equals("vpnv4") && !addrFamily.equals("vpnv6") && !addrFamily.equals("evpn")) {
session.getConsole().println("error: " + AF + " must be lu/evpn/vpnv4/vpnv6 ");
return null;
}
af_afi afi;
af_safi safi;
if (addrFamily.equals("vpnv6")) {
afi = af_afi.findByValue(2);
safi = af_safi.findByValue(5);
} else if (addrFamily.equals("evpn")) {
afi = af_afi.findByValue(3);
safi = af_safi.findByValue(6);
} else if (addrFamily.equals("lu")) {
afi = af_afi.findByValue(1);
safi = af_safi.findByValue(4);
} else {
// vpnv4
afi = af_afi.findByValue(1);
safi = af_safi.findByValue(5);
}
bgpManager.addAddressFamily(nbrIp, afi, safi);
}
break;
case "del":
if (nbrIp == null) {
session.getConsole().println("error: " + IP + " needed");
return null;
}
if (!Commands.isValid(session.getConsole(), nbrIp, Commands.Validators.IPADDR, IP)) {
return null;
}
if (asNum != null || multiHops != null || srcIp != null || addrFamily != null) {
session.getConsole().println("note: some option(s) not needed; ignored");
}
bgpManager.deleteNeighbor(nbrIp);
break;
default:
return usage();
}
return null;
}
Aggregations