Skip to content

Commit 4ab8f95

Browse files
committed
initial vibe
1 parent 0ebdc3d commit 4ab8f95

19 files changed

Lines changed: 1215 additions & 4 deletions

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ config :spark,
3737
]
3838

3939
config :diffo, ash_domains: [Diffo.Provider]
40-
config :diffo_example, ash_domains: [DiffoExample.Access]
40+
config :diffo_example, ash_domains: [DiffoExample.Access, DiffoExample.Nbn]
4141
import_config "#{config_env()}.exs"

lib/nbn/nbn.ex

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
Nbn - example NBN domain
10+
11+
Models NBN network resources including the Ethernet circuit (NbnEthernet)
12+
and its constituent resources: UNI (dedicated), AVC (dedicated), NTD,
13+
CVC (aggregates AVCs, terminates at NNI Group), NNI Group, and NNI.
14+
"""
15+
use Ash.Domain,
16+
otp_app: :diffo
17+
18+
alias DiffoExample.Nbn.NbnEthernet
19+
alias DiffoExample.Nbn.Uni
20+
alias DiffoExample.Nbn.Avc
21+
alias DiffoExample.Nbn.Ntd
22+
alias DiffoExample.Nbn.Cvc
23+
alias DiffoExample.Nbn.NniGroup
24+
alias DiffoExample.Nbn.Nni
25+
26+
domain do
27+
description "An example showing how TMF Resources for a fictional NBN domain can be extended from the Provider domain"
28+
end
29+
30+
resources do
31+
resource NbnEthernet do
32+
define :get_nbn_ethernet_by_id, action: :read, get_by: :id
33+
define :build_nbn_ethernet, action: :build
34+
define :define_nbn_ethernet, action: :define
35+
define :relate_nbn_ethernet, action: :relate
36+
end
37+
38+
resource Uni do
39+
define :get_uni_by_id, action: :read, get_by: :id
40+
define :build_uni, action: :build
41+
define :define_uni, action: :define
42+
define :relate_uni, action: :relate
43+
end
44+
45+
resource Avc do
46+
define :get_avc_by_id, action: :read, get_by: :id
47+
define :build_avc, action: :build
48+
define :define_avc, action: :define
49+
define :relate_avc, action: :relate
50+
end
51+
52+
resource Ntd do
53+
define :get_ntd_by_id, action: :read, get_by: :id
54+
define :build_ntd, action: :build
55+
define :define_ntd, action: :define
56+
define :relate_ntd, action: :relate
57+
end
58+
59+
resource Cvc do
60+
define :get_cvc_by_id, action: :read, get_by: :id
61+
define :build_cvc, action: :build
62+
define :define_cvc, action: :define
63+
define :assign_cvlan, action: :assign_cvlan
64+
define :relate_cvc, action: :relate
65+
end
66+
67+
resource NniGroup do
68+
define :get_nni_group_by_id, action: :read, get_by: :id
69+
define :build_nni_group, action: :build
70+
define :define_nni_group, action: :define
71+
define :assign_svlan, action: :assign_svlan
72+
define :relate_nni_group, action: :relate
73+
end
74+
75+
resource Nni do
76+
define :get_nni_by_id, action: :read, get_by: :id
77+
define :build_nni, action: :build
78+
define :define_nni, action: :define
79+
define :relate_nni, action: :relate
80+
end
81+
end
82+
end

lib/nbn/resources/avc.ex

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.Avc do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
Avc - Access Virtual Circuit Resource Instance
10+
11+
An AVC is the virtual circuit dedicated to an NBN Ethernet circuit,
12+
carrying traffic between its related UNI and the CVC that aggregates it.
13+
"""
14+
15+
alias Diffo.Provider.BaseInstance
16+
alias Diffo.Provider.Instance.Relationship
17+
alias Diffo.Provider.Instance.Characteristic
18+
alias Diffo.Provider.Instance.ActionHelper
19+
20+
alias DiffoExample.Nbn
21+
22+
use Ash.Resource,
23+
fragments: [BaseInstance],
24+
domain: Nbn
25+
26+
resource do
27+
description "An Ash Resource representing an Access Virtual Circuit (AVC)"
28+
plural_name :Avcs
29+
end
30+
31+
specification do
32+
id "b2c3d4e5-6f7a-4b8c-9d0e-1f2a3b4c5d6e"
33+
name "avc"
34+
type :resourceSpecification
35+
description "An AVC Resource Instance dedicated to an NBN Ethernet circuit"
36+
category "Network Resource"
37+
end
38+
39+
characteristics do
40+
characteristic :avc, DiffoExample.Nbn.AvcValue
41+
end
42+
43+
actions do
44+
create :build do
45+
description "creates a new AVC resource instance"
46+
accept [:id, :name, :type, :which]
47+
argument :specified_by, :uuid, public?: false
48+
argument :relationships, {:array, :struct}
49+
argument :features, {:array, :uuid}, public?: false
50+
argument :characteristics, {:array, :uuid}, public?: false
51+
argument :places, {:array, :struct}
52+
argument :parties, {:array, :struct}
53+
54+
change set_attribute(:type, :resource)
55+
56+
change before_action(fn changeset, _context -> ActionHelper.build_before(changeset) end)
57+
58+
change after_action(fn changeset, result, _context ->
59+
ActionHelper.build_after(changeset, result, Nbn, :get_avc_by_id)
60+
end)
61+
62+
change load [:href]
63+
upsert? false
64+
end
65+
66+
update :define do
67+
description "defines the AVC"
68+
argument :characteristic_value_updates, {:array, :term}
69+
70+
change after_action(fn changeset, result, _context ->
71+
with {:ok, result} <- Characteristic.update_values(result, changeset),
72+
{:ok, result} <- Nbn.get_avc_by_id(result.id),
73+
do: {:ok, result}
74+
end)
75+
end
76+
77+
update :relate do
78+
description "relates the AVC with other instances"
79+
argument :relationships, {:array, :struct}
80+
81+
change after_action(fn changeset, result, _context ->
82+
with {:ok, result} <- Relationship.relate_instance(result, changeset),
83+
{:ok, result} <- Nbn.get_avc_by_id(result.id),
84+
do: {:ok, result}
85+
end)
86+
end
87+
end
88+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.AvcValue do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
AvcValue - AshTyped Struct for AVC Characteristic Value
10+
"""
11+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
12+
13+
jason do
14+
pick [:cir, :pir]
15+
compact(true)
16+
end
17+
18+
outstanding do
19+
expect [:cir, :pir]
20+
end
21+
22+
typed_struct do
23+
field :cir, :integer, description: "Committed Information Rate in Mbps"
24+
25+
field :pir, :integer, description: "Peak Information Rate in Mbps"
26+
end
27+
28+
defimpl String.Chars do
29+
def to_string(struct) do
30+
inspect(struct)
31+
end
32+
end
33+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.CvcValue do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
CvcValue - AshTyped Struct for Connectivity Virtual Circuit Characteristic Value
10+
"""
11+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
12+
13+
jason do
14+
pick [:cvc_id, :bandwidth]
15+
compact(true)
16+
end
17+
18+
outstanding do
19+
expect [:cvc_id, :bandwidth]
20+
end
21+
22+
typed_struct do
23+
field :cvc_id, :string, description: "the unique CVC identifier"
24+
25+
field :bandwidth, :integer, description: "total CVC bandwidth in Mbps"
26+
end
27+
28+
defimpl String.Chars do
29+
def to_string(struct) do
30+
inspect(struct)
31+
end
32+
end
33+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.NbnEthernetValue do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
NbnEthernetValue - AshTyped Struct for NBN Ethernet Circuit Characteristic Value
10+
"""
11+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
12+
13+
jason do
14+
pick [:circuit_id, :speed, :technology]
15+
compact(true)
16+
end
17+
18+
outstanding do
19+
expect [:circuit_id, :speed]
20+
end
21+
22+
typed_struct do
23+
field :circuit_id, :string, description: "the unique NBN circuit identifier"
24+
25+
field :speed, :integer, description: "the circuit download speed in Mbps"
26+
27+
field :technology, :atom,
28+
description: "the access technology (:FTTP, :FTTN, :HFC, :Fixed_Wireless)"
29+
end
30+
31+
defimpl String.Chars do
32+
def to_string(struct) do
33+
inspect(struct)
34+
end
35+
end
36+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.NniGroupValue do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
NniGroupValue - AshTyped Struct for NNI Group Characteristic Value
10+
"""
11+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
12+
13+
jason do
14+
pick [:name, :location]
15+
compact(true)
16+
end
17+
18+
outstanding do
19+
expect [:name, :location]
20+
end
21+
22+
typed_struct do
23+
field :name, :string, description: "the NNI group name"
24+
25+
field :location, :string, description: "the Point of Interconnect (PoI) location"
26+
end
27+
28+
defimpl String.Chars do
29+
def to_string(struct) do
30+
inspect(struct)
31+
end
32+
end
33+
end
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.NniValue do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
NniValue - AshTyped Struct for NNI Characteristic Value
10+
"""
11+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
12+
13+
jason do
14+
pick [:port_id, :capacity, :technology]
15+
compact(true)
16+
end
17+
18+
outstanding do
19+
expect [:port_id, :capacity]
20+
end
21+
22+
typed_struct do
23+
field :port_id, :string, description: "the NNI port identifier"
24+
25+
field :capacity, :integer, description: "the NNI port capacity in Gbps"
26+
27+
field :technology, :atom, description: "the NNI technology (:Ethernet, :Fibre)"
28+
end
29+
30+
defimpl String.Chars do
31+
def to_string(struct) do
32+
inspect(struct)
33+
end
34+
end
35+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: 2025 diffo_example contributors <https://github.com/diffo-dev/diffo_example/graphs.contributors>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
defmodule DiffoExample.Nbn.NtdValue do
6+
@moduledoc """
7+
Diffo - TMF Service and Resource Management with a difference
8+
9+
NtdValue - AshTyped Struct for NTD Characteristic Value
10+
"""
11+
use Ash.TypedStruct, extensions: [AshJason.TypedStruct, AshOutstanding.TypedStruct]
12+
13+
jason do
14+
pick [:model, :serial_number, :technology]
15+
compact(true)
16+
end
17+
18+
outstanding do
19+
expect [:model, :serial_number]
20+
end
21+
22+
typed_struct do
23+
field :model, :string, description: "the NTD device model"
24+
25+
field :serial_number, :string, description: "the NTD serial number"
26+
27+
field :technology, :atom,
28+
description: "the access technology (:FTTP, :FTTN, :HFC, :Fixed_Wireless)"
29+
end
30+
31+
defimpl String.Chars do
32+
def to_string(struct) do
33+
inspect(struct)
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)