Skip to content

Instantly share code, notes, and snippets.

View jwbensley's full-sized avatar

James Bensley jwbensley

View GitHub Profile
@jwbensley
jwbensley / pdb_monocole.sh
Created July 15, 2026 07:04
An example BASH script which uses monocle to get the number of prefixes announce by each ASN in peeringDB with a non-zero prefix limit defined
#!/bin/bash
set -eu
# Example script which will get the number of IPv4 and IPv6 prefixes seen via each ASN in PeeringDB with a non-zero prefix limit.
# For example purposes; script is limited to the first 10 ASNs in PeeringDB, and one route collector, route-views.isc.
# Possible usage would be to query the broken API (https://status.broker.bgpkit.com/?tab=collectors) for a few route collectors
# which DON'T have this ASN connected, but DO have a few full table feeds each, to get a world view of that ASN.
# This script uses a locally built Monocle binary, the docker image can't be used until v1.4 is released:
# https://github.com/bgpkit/monocle/milestone/11
@jwbensley
jwbensley / AFPUB-2026-ASN-001-DRAFT02.txt
Last active June 8, 2026 09:21
AFPUB-2026-ASN-001-DRAFT01
Draft Policy Name: Require newly created AS-SETs to have hierarchical names
ID: AFPUB-2026-ASN-001-DRAFT01
Submission Date: 2026/05/15
Version: 2.0
Author(s):
(a) Name: James Bensley
(b) Email address: james@inter.link
(c) Affiliation: Inter.link GmbH
@jwbensley
jwbensley / main.rs
Created April 27, 2025 08:22
Parent / child traits in rust
trait Parent {
fn print_x(&self) {
println!("X is: {}", self.get_x());
}
fn get_x(&self) -> u16;
}
trait Child: Parent {
fn child_fn(&self) {
@jwbensley
jwbensley / ex-members.py
Created October 14, 2022 14:03
Depth first search of a tree with a per-branch "exclude" list
#!/usr/bin/env python3
"""
ASN to AS-SET mapping:
AS4200000011 -> AS-A1
AS4200000021 -> AS-B1
AS4200000022 -> AS-B2
AS4200000023 -> AS-B3
AS4200000031 -> AS-C1
AS4200000032 -> AS-C2
@jwbensley
jwbensley / memcpy_aligned.c
Created June 26, 2020 08:58
memcpy() using cache and page aligned values
#include <inttypes.h> // uint*_t
#include <stdio.h> // perror(), printf()
#include <stdlib.h> // memcpy, posix_memalign()
#include <string.h> // malloc()
#include <time.h> // clock_t, CLOCKS_PER_SEC
#include <unistd.h> // getpagesize()
static inline void memcpy_aligned(void *to, const void *from, size_t len) {
if (len <= 64) {
memcpy(to, from, 64);
// Not all functions are referenced below are called, that is intentional to verify that they are not being called.
// Provide timestamps:
function print_ts() {
ts = gettimeofday_us();
printf("[%10d.%06d] ", ts/1000000, ts%1000000);
}
#!/bin/bash
#
# Kills all iptables rules and unloads all iptables/netfilter related
# kernel modules.
#
# From: https://github.com/netoptimizer/network-testing/blob/master/bin/netfilter_unload_modules.sh
# Author: Jesper Dangaard Brouer <netoptimizer@brouer.com>
# Trick so, program can be run as normal user, will just use "sudo"
if [ "$EUID" -ne 0 ]; then
@jwbensley
jwbensley / grpc_cfg.py
Last active November 15, 2016 09:46
Example gRPC client for IOS-XR which loads a json plain text file and sends it over gRPC, using certificate authentication.
# Code from https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python/blob/master/examples/grpc_cfg.py
from grpc.framework.interfaces.face.face import AbortionError
import json
from time import sleep
import sys
sys.path.insert(0, '../')
from lib.cisco_grpc_client import CiscoGRPCClient