Diffo Example - NBN Domain
Mix.install(
[
{:diffo_example, "~> 0.2.0"}
],
consolidate_protocols: false
)
Overview
Diffo is a Telecommunications Management Forum (TMF) Service and Resource Manager, built for autonomous networks. It is implemented using the Ash Framework and stores data in Neo4j via AshNeo4j.
If you are new to Diffo, start with the Diffo livebook which introduces the core Provider concepts — Specification, Instance, Feature, Characteristic, Party, Place, and Relationship.
Diffo includes a Provider Instance extension that lets you declare specialised TMF Services and Resources using a Spark DSL with very little Elixir code. The Provider Instance Extension livebook covers this in detail.
The NBN domain in this example was built entirely with that DSL — a declarative model of a realistic NBN Ethernet access hierarchy with minimal custom Elixir, derived from a short domain description. It demonstrates how much can be expressed through the Provider extension alone.
The NBN domain models a fictional NBN Ethernet access circuit and its constituent resources:
- NbnEthernet — the parent circuit resource (identified by a PRI)
- UNI — User Network Interface at the customer premises
- AVC — Access Virtual Circuit (dedicated, carries traffic between UNI and CVC)
- NTD — Network Termination Device (installed at customer premises, assigns ports to UNI)
- CVC — Connectivity Virtual Circuit (aggregates AVCs, terminates at NNI Group)
- NNI Group — group of NNIs at the point of interconnect
- NNI — Network-to-Network Interface
Installing Neo4j and Configuring Bolty
Update the configuration below to match your Neo4j installation and evaluate.
config = [
uri: "bolt://localhost:7687",
auth: [username: "neo4j", password: "password"],
user_agent: "diffoExampleLivebook/1",
pool_size: 15,
max_overflow: 3,
prefix: :default,
name: Bolt,
log: false,
log_hex: false
]
AshNeo4j.BoltyHelper.start(config)
AshNeo4j.BoltyHelper.is_connected()
It is helpful to have a Neo4j browser open locally, typically at http://localhost:7474/browser/
OPTIONAL Clear the database before starting:
AshNeo4j.Neo4jHelper.delete_all()
Setup Aliases
require Ash.Query
alias DiffoExample.Nbn
alias DiffoExample.Nbn.NbnEthernet
alias DiffoExample.Nbn.Uni
alias DiffoExample.Nbn.Avc
alias DiffoExample.Nbn.Ntd
alias DiffoExample.Nbn.Cvc
alias DiffoExample.Nbn.NniGroup
alias DiffoExample.Nbn.Nni
alias DiffoExample.Nbn.Technology
alias DiffoExample.Nbn.Speeds
import Jason, only: [encode: 2]
About NBN
NBN (National Broadband Network) is Australia’s wholesale fixed-line access network, operated by NBN Co. It provides standardised access products to Retail Service Providers (RSPs), who in turn deliver internet and other services to end customers.
An RSP typically combines:
- An NBN Ethernet access circuit (UNI + AVC) at the customer premises — the access and aggregation layer modelled in this domain
- A home gateway device installed at the UNI, which provides the customer’s LAN, Wi-Fi, and sometimes voice
- Transport, aggregation, and edge infrastructure connecting the NNI to the RSP’s network and on to the internet
NBN Co connects the customer premises to the RSP’s network via a Point of Interconnect (POI). The NNI sits at the POI, grouped into NNI Groups. AVCs carrying customer traffic are aggregated onto a CVC, which terminates at the NNI Group. The RSP purchases CVC capacity to carry the aggregate traffic of its customers at that POI.
NBN is delivered over several access technologies — FTTP, FTTN, FTTB, FTTC, HFC, Fixed Wireless, and Satellite — which determine which bandwidth profiles and speeds are available to a given premises.
Technology and Speeds
The NBN domain defines Technology as an Ash Enum covering all NBN access types:
Technology.values()
Speeds are derived from a bandwidth_profile and technology combination. For example:
Speeds.speeds(:home_fast, :FTTP)
Speeds.speeds(:home_hyperfast, :HFC)
Speeds.speeds(:wireless_superfast, :FixedWireless)
# returns :error for invalid combinations
Speeds.speeds(:home_fast, :FixedWireless)
Building the Network Hinterland
Before we can provision an NBN Ethernet access we need the shared network resources: NNI, NNI Group, and CVC.
Build an NNI — the physical interconnect between the RSP and NBN Co:
nni = Nbn.build_nni!(%{})
nni |> Jason.encode!(pretty: true) |> IO.puts
Build an NNI Group — a logical grouping of NNIs at a point of interconnect:
nni_group = Nbn.build_nni_group!(%{})
nni_group |> Jason.encode!(pretty: true) |> IO.puts
Define the NNI Group with an SVLAN assignment and relate the NNI:
nni_group = Nbn.define_nni_group!(%{
characteristic_value_updates: [nni_group: [svlan: 100]]
})
nni_group = Nbn.relate_nni_group!(nni_group, %{
relationships: [%{alias: :nni, target_id: nni.id, type: :isAssigned}]
})
nni_group |> Jason.encode!(pretty: true) |> IO.puts
Build a CVC — the aggregation virtual circuit that terminates at the NNI Group:
cvc = Nbn.build_cvc!(%{})
cvc = Nbn.relate_cvc!(cvc, %{
relationships: [%{alias: :nni_group, target_id: nni_group.id, type: :isAssigned}]
})
cvc |> Jason.encode!(pretty: true) |> IO.puts
Provisioning an NBN Ethernet Access
With the hinterland in place we can provision a customer-facing NBN Ethernet access.
Build an NTD — the device installed at the customer premises:
ntd = Nbn.build_ntd!(%{})
ntd = Nbn.define_ntd!(ntd, %{
characteristic_value_updates: [ntd: [technology: :FTTP, ports: [1, 2, 3, 4]]]
})
ntd |> Jason.encode!(pretty: true) |> IO.puts
Build a UNI — the interface at the customer premises — and assign a port from the NTD:
uni = Nbn.build_uni!(%{})
alias Diffo.Provider.Assignment
ntd = Nbn.assign_port!(ntd, %{
assignment: %Assignment{assignee_id: uni.id, value: 1}
})
ntd |> Jason.encode!(pretty: true) |> IO.puts
Relate the UNI back to the NTD so it can mine technology and port from it:
uni = Nbn.relate_uni!(uni, %{
relationships: [%{alias: :ntd, target_id: ntd.id, type: :isAssigned}]
})
uni = Nbn.mine_uni!(uni, %{})
uni |> Jason.encode!(pretty: true) |> IO.puts
Build an AVC and assign it a CVLAN from the CVC:
avc = Nbn.build_avc!(%{})
avc = Nbn.define_avc!(avc, %{
characteristic_value_updates: [avc: [bandwidth_profile: :home_ultrafast]]
})
cvc = Nbn.assign_cvlan!(cvc, %{
assignment: %Assignment{assignee_id: avc.id, value: 200}
})
avc = Nbn.mine_avc!(avc, %{})
avc |> Jason.encode!(pretty: true) |> IO.puts
Now build the top-level NBN Ethernet access and relate it to both the UNI and AVC:
pri = Nbn.build_nbn_ethernet!(%{})
pri = Nbn.relate_nbn_ethernet!(pri, %{
relationships: [
%{alias: :uni, target_id: uni.id, type: :isAssigned},
%{alias: :avc, target_id: avc.id, type: :isAssigned}
]
})
pri = Nbn.mine_nbn_ethernet!(pri, %{})
pri |> Jason.encode!(pretty: true) |> IO.puts
The mine action on NbnEthernet extracts technology from the UNI and bandwidth_profile from the AVC and derives the speeds automatically.
Exploring the Graph
You can query all nodes and relationships in Neo4j browser with:
MATCH (n1)-[r]->(n2) RETURN r, n1, n2 LIMIT 50
Or from Elixir:
AshNeo4j.Cypher.run("MATCH (n1)-[r]->(n2) RETURN r, n1, n2 LIMIT 50")
What Next?
You’ve provisioned a complete NBN Ethernet access — NTD, UNI, AVC, CVC, NNI Group, and NNI — and seen how the mine actions propagate technology, speeds, CVLAN and port assignments up the resource hierarchy automatically.
The Access domain in diffo_example shows a similar pattern for DSL access services. Explore lib/access/ for copper-network equivalents (Cable, Card, Path, Shelf).
If you find Diffo useful please visit and star on GitHub.