summaryrefslogtreecommitdiffstats
path: root/tests/lib/test_grpc.cpp
blob: 202313603d0e9a5f022550346715bad712e40c93 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * May 16 2021, Christian Hopps <chopps@labn.net>
 *
 * Copyright (c) 2021, LabN Consulting, L.L.C
 */

#include <time.h>
#include <unistd.h>
#include <zebra.h>

#include "filter.h"
#include "frr_pthread.h"
#include "libfrr.h"
#include "routing_nb.h"
#include "northbound_cli.h"
#include "frrevent.h"
#include "vrf.h"
#include "vty.h"

#include "staticd/static_debug.h"
#include "staticd/static_nb.h"
#include "staticd/static_vrf.h"
#include "staticd/static_vty.h"
#include "staticd/static_zebra.h"

// GRPC C++ includes
#include <string>
#include <sstream>
#include <grpc/grpc.h>
#include <grpcpp/channel.h>
#include <grpcpp/client_context.h>
#include <grpcpp/create_channel.h>
#include <grpcpp/security/credentials.h>
#include "grpc/frr-northbound.grpc.pb.h"

DEFINE_HOOK(test_grpc_late_init, (struct event_loop * tm), (tm));
DEFINE_KOOH(test_grpc_fini, (), ());

struct vty *vty;

bool mpls_enabled;
struct event_loop *master;
struct zebra_privs_t static_privs = {0};
struct frrmod_runtime *grpc_module;
char binpath[2 * MAXPATHLEN + 1];

extern const char *json_expect1;
extern const char *json_expect2;
extern const char *json_expect3;
extern const char *json_loadconf1;

int test_dbg = 1;

void inline test_debug(const std::string &s)
{
	if (test_dbg)
		std::cout << s << std::endl;
}

// static struct option_chain modules[] = {{ .arg = "grpc:50051" }]
// static struct option_chain **modnext = modules->next;

static const struct frr_yang_module_info *const staticd_yang_modules[] = {
	&frr_interface_info, &frr_filter_info, &frr_routing_info,
	&frr_staticd_info,   &frr_vrf_info,
};

static void grpc_thread_stop(struct event *thread);

static void _err_print(const void *cookie, const char *errstr)
{
	std::cout << "Failed to load grpc module:" << errstr << std::endl;
}

static void static_startup(void)
{
	// struct frrmod_runtime module;
	// static struct option_chain *oc;

	cmd_init(1);

	zlog_aux_init("NONE: ", LOG_DEBUG);
	zprivs_preinit(&static_privs);
	zprivs_init(&static_privs);

	/* Load the server side module -- check libtool path first */
	std::string modpath = std::string(binpath) + std::string("../../lib/.libs");
	grpc_module = frrmod_load("grpc:50051", modpath.c_str(), 0, 0);
	if (!grpc_module) {
		modpath = std::string(binpath) +  std::string("../../lib");
		grpc_module = frrmod_load("grpc:50051", modpath.c_str(),
					  _err_print, 0);
	}
	if (!grpc_module) {
		modpath = std::string(binpath) +
			  std::string("../../../lib/.libs");
		grpc_module = frrmod_load("grpc:50051", modpath.c_str(),
					  _err_print, 0);
	}
	if (!grpc_module) {
		modpath = std::string(binpath) + std::string("../../../lib");
		grpc_module = frrmod_load("grpc:50051", modpath.c_str(),
					  _err_print, 0);
	}
	if (!grpc_module)
		exit(1);

	static_debug_init();

	master = event_master_create(NULL);
	nb_init(master, staticd_yang_modules, array_size(staticd_yang_modules),
		false);

	static_zebra_init();
	vty_init(master, true);
	static_vrf_init();
	static_vty_init();

	hook_register(routing_conf_event,
		      routing_control_plane_protocols_name_validate);
	hook_register(routing_create,
		      routing_control_plane_protocols_staticd_create);
	hook_register(routing_destroy,
		      routing_control_plane_protocols_staticd_destroy);

	// Add a route
	vty = vty_new();
	vty->type = vty::VTY_TERM;
	vty_config_enter(vty, true, false, false);

	auto ret = cmd_execute(vty, "ip route 11.0.0.0/8 Null0", NULL, 0);
	assert(!ret);

	ret = cmd_execute(vty, "end", NULL, 0);
	assert(!ret);

	nb_cli_pending_commit_check(vty);

	frr_pthread_init();

	// frr_config_fork();
	hook_call(test_grpc_late_init, master);
}

static void static_shutdown(void)
{
	hook_call(test_grpc_fini);
	vty_close(vty);
	vrf_terminate();
	vty_terminate();
	cmd_terminate();
	nb_terminate();
	yang_terminate();
	event_master_free(master);
	master = NULL;
}

using frr::Northbound;
using grpc::Channel;
using grpc::ClientAsyncResponseReader;
using grpc::ClientContext;
using grpc::CompletionQueue;
using grpc::Status;

class NorthboundClient
{
      public:
	NorthboundClient(std::shared_ptr<Channel> channel)
	    : stub_(frr::Northbound::NewStub(channel))
	{
	}

	void Commit(uint32_t candidate_id)
	{
		frr::CommitRequest request;
		frr::CommitResponse reply;
		ClientContext context;
		Status status;

		request.set_candidate_id(candidate_id);

		request.set_phase(frr::CommitRequest::ALL);
		status = stub_->Commit(&context, request, &reply);
		_throw_if_not_ok(status);
#if 0
		request.set_phase(frr::CommitRequest::VALIDATE);
		status = stub_->Commit(&context, request, &reply);
		_throw_if_not_ok(status);

		request.set_phase(frr::CommitRequest::PREPARE);
		status = stub_->Commit(&context, request, &reply);
		_throw_if_not_ok(status);

		request.set_phase(frr::CommitRequest::APPLY);
		status = stub_->Commit(&context, request, &reply);
		_throw_if_not_ok(status);
#endif
	}

	uint32_t CreateCandidate()
	{
		frr::CreateCandidateRequest request;
		frr::CreateCandidateResponse reply;
		ClientContext context;
		Status status;

		status = stub_->CreateCandidate(&context, request, &reply);
		_throw_if_not_ok(status);
		return reply.candidate_id();
	}

	void DeleteCandidate(uint32_t candidate_id)
	{
		frr::DeleteCandidateRequest request;
		frr::DeleteCandidateResponse reply;
		ClientContext context;
		Status status;

		request.set_candidate_id(candidate_id);
		status = stub_->DeleteCandidate(&context, request, &reply);
		_throw_if_not_ok(status);
	}

	void EditCandidate(uint32_t candidate_id, const std::string &path,
			   const std::string &value)
	{
		frr::EditCandidateRequest request;
		frr::EditCandidateResponse reply;
		ClientContext context;

		request.set_candidate_id(candidate_id);
		frr::PathValue *pv = request.add_update();
		pv->set_path(path);
		pv->set_value(value);

		Status status = stub_->EditCandidate(&context, request, &reply);
		_throw_if_not_ok(status);
	}

	std::string Get(const std::string &path,
			frr::GetRequest::DataType dtype, frr::Encoding enc,
			bool with_defaults)
	{
		frr::GetRequest request;
		frr::GetResponse reply;
		ClientContext context;
		std::ostringstream ss;

		request.set_type(dtype);
		request.set_encoding(enc);
		request.set_with_defaults(with_defaults);
		request.add_path(path);

		auto stream = stub_->Get(&context, request);
		while (stream->Read(&reply)) {
			ss << reply.data().data() << std::endl;
		}
		auto status = stream->Finish();
		_throw_if_not_ok(status);
		return ss.str();
	}

	std::string GetCapabilities()
	{
		frr::GetCapabilitiesRequest request;
		frr::GetCapabilitiesResponse reply;
		ClientContext context;

		Status status =
			stub_->GetCapabilities(&context, request, &reply);
		_throw_if_not_ok(status);

		std::ostringstream ss;
		ss << "Capabilities:" << std::endl
		   << "\tVersion: " << reply.frr_version() << std::endl
		   << "\tRollback Support: " << reply.rollback_support()
		   << std::endl
		   << "\tSupported Modules:";

		for (int i = 0; i < reply.supported_modules_size(); i++) {
			auto sm = reply.supported_modules(i);
			ss << std::endl
			   << "\t\tName: \"" << sm.name()
			   << "\" Revision: " << sm.revision() << " Org: \""
			   << sm.organization() << "\"";
		}

		ss << std::endl << "\tSupported Encodings:";

		for (int i = 0; i < reply.supported_encodings_size(); i++) {
			auto se = reply.supported_encodings(i);
			auto desc =
				google::protobuf::GetEnumDescriptor<decltype(
					se)>();
			ss << std::endl
			   << "\t\t" << desc->FindValueByNumber(se)->name();
		}

		ss << std::endl;

		return ss.str();
	}

	void LoadToCandidate(uint32_t candidate_id, bool is_replace,
			     bool is_json, const std::string &data)
	{
		frr::LoadToCandidateRequest request;
		frr::LoadToCandidateResponse reply;
		frr::DataTree *dt = new frr::DataTree;
		ClientContext context;

		request.set_candidate_id(candidate_id);
		request.set_type(is_replace
					 ? frr::LoadToCandidateRequest::REPLACE
					 : frr::LoadToCandidateRequest::MERGE);
		dt->set_encoding(is_json ? frr::JSON : frr::XML);
		dt->set_data(data);
		request.set_allocated_config(dt);

		Status status =
			stub_->LoadToCandidate(&context, request, &reply);
		_throw_if_not_ok(status);
	}

	std::string ListTransactions()
	{
		frr::ListTransactionsRequest request;
		frr::ListTransactionsResponse reply;
		ClientContext context;
		std::ostringstream ss;

		auto stream = stub_->ListTransactions(&context, request);

		while (stream->Read(&reply)) {
			ss << "Tx ID: " << reply.id()
			   << " client: " << reply.client()
			   << " date: " << reply.date()
			   << " comment: " << reply.comment() << std::endl;
		}

		auto status = stream->Finish();
		_throw_if_not_ok(status);
		return ss.str();
	}

      private:
	std::unique_ptr<frr::Northbound::Stub> stub_;

	void _throw_if_not_ok(Status &status)
	{
		if (!status.ok())
			throw std::runtime_error(
				std::to_string(status.error_code()) + ": "
				+ status.error_message());
	}
};


bool stop = false;

int grpc_client_test_stop(struct frr_pthread *fpt, void **result)
{
	test_debug("client: STOP pthread");

	assert(fpt->running);
	atomic_store_explicit(&fpt->running, false, memory_order_relaxed);

	test_debug("client: joining pthread");
	pthread_join(fpt->thread, result);

	test_debug("client: joined pthread");
	return 0;
}

int find_first_diff(const std::string &s1, const std::string &s2)
{
	int s1len = s1.length();
	int s2len = s2.length();
	int mlen = std::min(s1len, s2len);

	for (int i = 0; i < mlen; i++)
		if (s1[i] != s2[i])
			return i;
	return s1len == s2len ? -1 : mlen;
}

void assert_no_diff(const std::string &s1, const std::string &s2)
{
	int pos = find_first_diff(s1, s2);
	if (pos == -1)
		return;
	std::cout << "not ok" << std::endl;
	std::cout << "Same: " << s1.substr(0, pos) << std::endl;
	std::cout << "Diff s1: " << s1.substr(pos) << std::endl;
	std::cout << "Diff s2: " << s2.substr(pos) << std::endl;
	assert(false);
}

void assert_config_same(NorthboundClient &client, const std::string &compare)
{
	std::string confs = client.Get("/frr-routing:routing",
				       frr::GetRequest::ALL, frr::JSON, true);
	assert_no_diff(confs, compare);
	std::cout << "ok" << std::endl;
}

void grpc_client_run_test(void)
{
	NorthboundClient client(grpc::CreateChannel(
		"localhost:50051", grpc::InsecureChannelCredentials()));

	std::string reply = client.GetCapabilities();

	uint32_t cid;
	cid = client.CreateCandidate();
	std::cout << "CreateCandidate -> " << cid << std::endl;
	assert(cid == 1);
	client.DeleteCandidate(cid);
	std::cout << "DeleteCandidate(" << cid << ")" << std::endl;
	cid = client.CreateCandidate();
	assert(cid == 2);
	std::cout << "CreateCandidate -> " << cid << std::endl;

	/*
	 * Get initial configuration
	 */
	std::cout << "Comparing initial config...";
	assert_config_same(client, json_expect1);

	/*
	 * Add config using EditCandidate
	 */

	char xpath_buf[1024];
	strlcpy(xpath_buf,
		"/frr-routing:routing/control-plane-protocols/"
		"control-plane-protocol[type='frr-staticd:staticd']"
		"[name='staticd'][vrf='default']/frr-staticd:staticd/route-list",
		sizeof(xpath_buf));
	int slen = strlen(xpath_buf);
	for (int i = 0; i < 4; i++) {
		snprintf(xpath_buf + slen, sizeof(xpath_buf) - slen,
			 "[prefix='13.0.%d.0/24']"
			 "[afi-safi='frr-routing:ipv4-unicast']/"
			 "path-list[table-id='0'][distance='1']/"
			 "frr-nexthops/nexthop[nh-type='blackhole']"
			 "[vrf='default'][gateway=''][interface='(null)']",
			 i);
		client.EditCandidate(cid, xpath_buf, "");
	}
	client.Commit(cid);
	std::cout << "Comparing EditCandidate config...";
	assert_config_same(client, json_expect2);

	client.DeleteCandidate(cid);
	std::cout << "DeleteCandidate(" << cid << ")" << std::endl;

	/*
	 * Add config using LoadToCandidate
	 */

	cid = client.CreateCandidate();
	std::cout << "CreateCandidate -> " << cid << std::endl;

	client.LoadToCandidate(cid, false, true, json_loadconf1);
	client.Commit(cid);

	std::cout << "Comparing LoadToCandidate config...";
	assert_config_same(client, json_expect3);

	client.DeleteCandidate(cid);
	std::cout << "DeleteCandidate(" << cid << ")" << std::endl;

	std::string ltxreply = client.ListTransactions();
	// std::cout << "client: pthread received: " << ltxreply << std::endl;
}

void *grpc_client_test_start(void *arg)
{
	struct frr_pthread *fpt = (struct frr_pthread *)arg;
	fpt->master->owner = pthread_self();
	frr_pthread_set_name(fpt);
	frr_pthread_notify_running(fpt);

	try {
		grpc_client_run_test();
		std::cout << "TEST PASSED" << std::endl;
	} catch (std::exception &e) {
		std::cout << "Exception in test: " << e.what() << std::endl;
	}

	// Signal FRR event loop to stop
	test_debug("client: pthread: adding event to stop us");
	event_add_event(master, grpc_thread_stop, NULL, 0, NULL);

	test_debug("client: pthread: DONE (returning)");

	return NULL;
}

static void grpc_thread_start(struct event *thread)
{
	struct frr_pthread_attr client = {
		.start = grpc_client_test_start,
		.stop = grpc_client_test_stop,
	};

	auto pth = frr_pthread_new(&client, "GRPC Client thread", "grpc");
	frr_pthread_run(pth, NULL);
	frr_pthread_wait_running(pth);
}

static void grpc_thread_stop(struct event *thread)
{
	std::cout << __func__ << ": frr_pthread_stop_all" << std::endl;
	frr_pthread_stop_all();
	std::cout << __func__ << ": static_shutdown" << std::endl;
	static_shutdown();
	std::cout << __func__ << ": exit cleanly" << std::endl;
	exit(0);
}

/*
 * return abs path to this binary with trailing `/`. Does not parse path
 * environment to find in path, which should not matter for unit testing.
 */
static int get_binpath(const char *argv0, char cwd[2 * MAXPATHLEN + 1])
{
	const char *rch;
	if (argv0[0] == '/') {
		*cwd = 0;
		rch = strrchr(argv0, '/');
		strlcpy(cwd, argv0, MIN(rch - argv0 + 2, 2 * MAXPATHLEN + 1));
		return 0;
	}
	if (!(rch = strrchr(argv0, '/'))) {
		/* Does not handle using PATH, shouldn't matter for test */
		errno = EINVAL;
		return -1;
	}
	if (!getcwd(cwd, MAXPATHLEN))
		return -1;
	int len = strlen(cwd);
	cwd[len++] = '/';
	strlcpy(cwd + len, argv0, MIN(rch - argv0 + 2, 2 * MAXPATHLEN + 1));
	return 0;
}

int main(int argc, char **argv)
{
	assert(argc >= 1);
	if (get_binpath(argv[0], binpath) < 0)
		exit(1);

	static_startup();

	event_add_event(master, grpc_thread_start, NULL, 0, NULL);

	/* Event Loop */
	struct event thread;
	while (event_fetch(master, &thread))
		event_call(&thread);
	return 0;
}

// clang-format off

const char *json_expect1 = R"NONCE({
  "frr-routing:routing": {
    "control-plane-protocols": {
      "control-plane-protocol": [
        {
          "type": "frr-staticd:staticd",
          "name": "staticd",
          "vrf": "default",
          "frr-staticd:staticd": {
            "route-list": [
              {
                "prefix": "11.0.0.0/8",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "frr-vrf:lib": {
    "vrf": [
      {
        "name": "default",
        "state": {
          "active": false
        }
      }
    ]
  }
}

)NONCE";

const char *json_loadconf1 = R"NONCE(
{
  "frr-routing:routing": {
    "control-plane-protocols": {
      "control-plane-protocol": [
        {
          "type": "frr-staticd:staticd",
          "name": "staticd",
          "vrf": "default",
          "frr-staticd:staticd": {
            "route-list": [
              {
                "prefix": "10.0.0.0/13",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)"
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "frr-vrf:lib": {
    "vrf": [
      {
        "name": "default"
      }
    ]
  }
})NONCE";

const char *json_expect2 = R"NONCE({
  "frr-routing:routing": {
    "control-plane-protocols": {
      "control-plane-protocol": [
        {
          "type": "frr-staticd:staticd",
          "name": "staticd",
          "vrf": "default",
          "frr-staticd:staticd": {
            "route-list": [
              {
                "prefix": "11.0.0.0/8",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.0.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.1.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.2.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.3.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "frr-vrf:lib": {
    "vrf": [
      {
        "name": "default",
        "state": {
          "active": false
        }
      }
    ]
  }
}

)NONCE";

const char *json_expect3 = R"NONCE({
  "frr-routing:routing": {
    "control-plane-protocols": {
      "control-plane-protocol": [
        {
          "type": "frr-staticd:staticd",
          "name": "staticd",
          "vrf": "default",
          "frr-staticd:staticd": {
            "route-list": [
              {
                "prefix": "11.0.0.0/8",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.0.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.1.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.2.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "13.0.3.0/24",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              },
              {
                "prefix": "10.0.0.0/13",
                "afi-safi": "frr-routing:ipv4-unicast",
                "path-list": [
                  {
                    "table-id": 0,
                    "distance": 1,
                    "tag": 0,
                    "frr-nexthops": {
                      "nexthop": [
                        {
                          "nh-type": "blackhole",
                          "vrf": "default",
                          "gateway": "",
                          "interface": "(null)",
                          "bh-type": "null",
                          "onlink": false
                        }
                      ]
                    }
                  }
                ]
              }
            ]
          }
        }
      ]
    }
  },
  "frr-vrf:lib": {
    "vrf": [
      {
        "name": "default",
        "state": {
          "active": false
        }
      }
    ]
  }
}

)NONCE";