-
Notifications
You must be signed in to change notification settings - Fork 74
/
bgp_create.cpp
96 lines (80 loc) · 3.36 KB
/
bgp_create.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ----------------------------------------------------------------
Copyright 2016 Cisco Systems
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
------------------------------------------------------------------*/
#include <iostream>
#include <spdlog/spdlog.h>
#include "ydk/netconf_provider.hpp"
#include "ydk/crud_service.hpp"
#include "ydk_openconfig/openconfig_bgp.hpp"
#include "ydk_openconfig/openconfig_bgp_types.hpp"
#include "args_parser.h"
using namespace ydk;
using namespace openconfig;
using namespace std;
void config_bgp(openconfig_bgp::Bgp* bgp)
{
// Set the Global AS
bgp->global->config->as = 65172;
bgp->global->config->router_id = "1.2.3.4";
auto afi_safi = make_shared<openconfig_bgp::Bgp::Global::AfiSafis::AfiSafi>();
afi_safi->afi_safi_name = openconfig_bgp_types::L3VPNIPV4UNICAST();
afi_safi->config->afi_safi_name = openconfig_bgp_types::L3VPNIPV4UNICAST();
afi_safi->config->enabled = false;
bgp->global->afi_safis->afi_safi.append(afi_safi);
auto neighbor = make_shared<openconfig_bgp::Bgp::Neighbors::Neighbor>();
neighbor->neighbor_address = "6.7.8.9";
neighbor->config->neighbor_address = "6.7.8.9";
neighbor->config->peer_as = 65001;
neighbor->config->local_as = 65001;
neighbor->config->peer_group = "IBGP";
//neighbor->config->peer_type = "INTERNAL";
//neighbor->config->remove_private_as = openconfig_bgp_types::PRIVATEASREMOVEALL();
bgp->neighbors->neighbor.append(neighbor);
auto peer_group = make_shared<openconfig_bgp::Bgp::PeerGroups::PeerGroup>();
peer_group->peer_group_name = "IBGP";
peer_group->config->peer_group_name = "IBGP";
//peer_group->config->auth_password = "password";
peer_group->config->description = "test description";
peer_group->config->peer_as = 65001;
peer_group->config->local_as = 65001;
//peer_group->config->peer_type = "INTERNAL";
//peer_group->config->remove_private_as = openconfig_bgp_types::PRIVATEASREMOVEALL();
bgp->peer_groups->peer_group.append(peer_group);
}
int main(int argc, char* argv[])
{
vector<string> args = parse_args(argc, argv);
if(args.empty()) return 1;
string host, username, password;
int port;
username = args[0]; password = args[1]; host = args[2]; port = stoi(args[3]);
bool verbose=(args[4]=="--verbose");
if(verbose)
{
auto logger = spdlog::stdout_color_mt("ydk");
logger->set_level(spdlog::level::info);
}
try {
NetconfServiceProvider provider{host, username, password, port};
CrudService crud{};
auto bgp = make_unique<openconfig_bgp::Bgp>();
config_bgp(bgp.get());
bool reply = crud.create(provider, *bgp);
if (reply)
cout << "Create yfilter success" << endl << endl;
else
cout << "Operation failed" << endl << endl;
}
catch(YError & e) {
cerr << "Error details: "<<e<<endl;
}
}