diff --git a/app/Classes/FTN/Packet.php b/app/Classes/FTN/Packet.php
index 96442bd..37aa4a4 100644
--- a/app/Classes/FTN/Packet.php
+++ b/app/Classes/FTN/Packet.php
@@ -10,7 +10,6 @@ use Illuminate\Support\Facades\Log;
use Symfony\Component\HttpFoundation\File\File;
use App\Classes\FTN as FTNBase;
-use App\Http\Controllers\DomainController;
use App\Models\{Address,Setup,Software,System,Zone};
class Packet extends FTNBase implements \Iterator, \Countable
@@ -462,7 +461,7 @@ class Packet extends FTNBase implements \Iterator, \Countable
}
$ao->active = TRUE;
- $ao->role = DomainController::NODE_UNKNOWN;
+ $ao->role = Address::NODE_UNKNOWN;
System::unguard();
$so = System::firstOrCreate([
diff --git a/app/Classes/Protocol.php b/app/Classes/Protocol.php
index 42cd6a2..8a1a6d3 100644
--- a/app/Classes/Protocol.php
+++ b/app/Classes/Protocol.php
@@ -194,7 +194,7 @@ abstract class Protocol
$addresses = collect();
foreach (($this->originate ? $this->node->aka_remote_authed : $this->node->aka_remote) as $ao)
- $addresses = $addresses->merge($this->setup->system->match($ao->zone));
+ $addresses = $addresses->merge($this->setup->system->match($ao->zone,Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT));
$addresses = $addresses->unique();
diff --git a/app/Classes/Protocol/Binkp.php b/app/Classes/Protocol/Binkp.php
index 475681f..77a6d5f 100644
--- a/app/Classes/Protocol/Binkp.php
+++ b/app/Classes/Protocol/Binkp.php
@@ -154,7 +154,7 @@ final class Binkp extends BaseProtocol
$addresses = collect();
foreach ($this->node->aka_remote_authed as $ao)
- $addresses = $addresses->merge($this->setup->system->match($ao->zone));
+ $addresses = $addresses->merge($this->setup->system->match($ao->zone,Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC|Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT));
$addresses = $addresses->unique();
diff --git a/app/Http/Controllers/DomainController.php b/app/Http/Controllers/DomainController.php
index f43875d..c9350dd 100644
--- a/app/Http/Controllers/DomainController.php
+++ b/app/Http/Controllers/DomainController.php
@@ -9,17 +9,6 @@ use App\Models\{Address,Domain,Zone};
class DomainController extends Controller
{
- public const NODE_ACTIVE = 0; // Active
- public const NODE_ZC = 1<<0; // Zone
- public const NODE_RC = 1<<1; // Region
- public const NODE_NC = 1<<2; // Host
- public const NODE_HC = 1<<3; // Hub
- public const NODE_POINT = 1<<4; // Point
- public const NODE_PVT = 1<<5; // Pvt
- public const NODE_HOLD = 1<<6; // Hold
- public const NODE_DOWN = 1<<7; // Down
- public const NODE_UNKNOWN = 1<<8; // Down
-
// http://ftsc.org/docs/frl-1002.001
public const NUMBER_MAX = 0x7fff;
@@ -65,7 +54,7 @@ class DomainController extends Controller
*/
public function api_hosts(Zone $o,int $region): Collection
{
- $oo = Address::where('role',self::NODE_NC)
+ $oo = Address::where('role',Address::NODE_NC)
->where('zone_id',$o->id)
->when($region,function($query,$region) { return $query->where('region_id',$region)->where('node_id',0); })
->when((! $region),function($query) use ($region) { return $query->where('region_id',0); })
@@ -107,7 +96,7 @@ class DomainController extends Controller
*/
public function api_regions(Zone $o): Collection
{
- $oo = Address::where('role',self::NODE_RC)
+ $oo = Address::where('role',Address::NODE_RC)
->where('zone_id',$o->id)
->where('node_id',0)
->where('point_id',0)
diff --git a/app/Http/Controllers/SystemController.php b/app/Http/Controllers/SystemController.php
index 4794252..ae9a560 100644
--- a/app/Http/Controllers/SystemController.php
+++ b/app/Http/Controllers/SystemController.php
@@ -53,13 +53,13 @@ class SystemController extends Controller
->where('host_id',0)
->where('node_id',0)
->where('point_id',0)
- ->where('role',DomainController::NODE_RC);
+ ->where('role',Address::NODE_RC);
})
// Check that a host doesnt already exist
->orWhere(function($query) use ($value) {
return $query->where('host_id',$value)
->where('point_id',0)
- ->where('role',DomainController::NODE_NC);
+ ->where('role',Address::NODE_NC);
});
if ($o->count()) {
@@ -75,7 +75,7 @@ class SystemController extends Controller
$oo->host_id = 0;
$oo->node_id = 0;
$oo->point_id = 0;
- $oo->role = DomainController::NODE_RC;
+ $oo->role = Address::NODE_RC;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -92,12 +92,12 @@ class SystemController extends Controller
$o = Address::where(function($query) use ($value) {
return $query->where(function($query) use ($value) {
return $query->where('region_id',$value)
- ->where('role',DomainController::NODE_RC);
+ ->where('role',Address::NODE_RC);
})
// Check that a host doesnt already exist
->orWhere(function($query) use ($value) {
return $query->where('host_id',$value)
- ->where('role',DomainController::NODE_NC);
+ ->where('role',Address::NODE_NC);
});
})
->where('zone_id',$request->post('zone_id'))
@@ -119,7 +119,7 @@ class SystemController extends Controller
->where('host_id',$request->post('host_id_new'))
->where('node_id',$value)
->where('point_id',0)
- ->where('role',DomainController::NODE_RC);
+ ->where('role',Address::NODE_RC);
});
if ($o->count()) {
@@ -147,7 +147,7 @@ class SystemController extends Controller
'host_id'=>$request->host_id_new,
'node_id'=>0,
'point_id'=>0,
- 'role'=>DomainController::NODE_NC,
+ 'role'=>Address::NODE_NC,
]);
}
@@ -161,7 +161,7 @@ class SystemController extends Controller
$oo->host_id = $request->post('host_id_new');
$oo->node_id = $request->post('node_id_new');
$oo->point_id = 0;
- $oo->role = DomainController::NODE_NC;
+ $oo->role = Address::NODE_NC;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -204,7 +204,7 @@ class SystemController extends Controller
$oo->node_id = $request->post('node_id');
$oo->point_id = $request->post('point_id');
$oo->hub_id = $request->post('hub_id') > 0 ? $request->post('hub_id') : NULL;
- $oo->role = (! $oo->point_id) && $request->post('hub') ? DomainController::NODE_HC : NULL;
+ $oo->role = (! $oo->point_id) && $request->post('hub') ? Address::NODE_HC : Address::NODE_ACTIVE;
$oo->active = TRUE;
$o->addresses()->save($oo);
@@ -242,7 +242,7 @@ class SystemController extends Controller
$zo = Zone::findOrFail($validate['zone_id']);
// If this session is for the ZC, it now becomes the default.
- if (in_array(DomainController::NODE_ZC,$o->match($zo)->pluck('role')->toArray())) {
+ if ($o->match($zo,Address::NODE_ZC)->count()) {
SystemZone::where('default',TRUE)->update(['default'=>FALSE]);
$validate['default'] = TRUE;
}
diff --git a/app/Http/Controllers/ZoneController.php b/app/Http/Controllers/ZoneController.php
index 97824e3..a7f20ca 100644
--- a/app/Http/Controllers/ZoneController.php
+++ b/app/Http/Controllers/ZoneController.php
@@ -93,7 +93,7 @@ class ZoneController extends Controller
'host_id'=>0,
'node_id'=>0,
'point_id'=>0,
- 'role'=>DomainController::NODE_ZC,
+ 'role'=>Address::NODE_ZC,
]);
}
@@ -121,7 +121,7 @@ class ZoneController extends Controller
$default = $o->systems->where('pivot.default',TRUE);
- if ($default->count() && $default->first()->addresses->pluck('role')->search(DomainController::NODE_ZC) !== FALSE)
+ if ($default->count() && $default->first()->addresses->pluck('role')->search(Address::NODE_ZC) !== FALSE)
abort(412);
if ($default->count() && ($default->first()->id != $request->sid))
diff --git a/app/Jobs/NodelistImport.php b/app/Jobs/NodelistImport.php
index 08a8689..9d2c150 100644
--- a/app/Jobs/NodelistImport.php
+++ b/app/Jobs/NodelistImport.php
@@ -12,7 +12,6 @@ use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
-use App\Http\Controllers\DomainController;
use App\Models\{Address,Domain,Nodelist,Setup,System,Zone};
use App\Traits\Import as ImportTrait;
@@ -134,13 +133,13 @@ class NodelistImport implements ShouldQueue
$region = 0;
$host = 0;
$hub_id = NULL;
- $role = DomainController::NODE_ZC;
+ $role = Address::NODE_ZC;
break;
case 'Region':
$region = $fields[1];
- $role = DomainController::NODE_RC;
+ $role = Address::NODE_RC;
$host = 0;
$hub_id = NULL;
@@ -149,36 +148,37 @@ class NodelistImport implements ShouldQueue
case 'Host':
$host = $fields[1];
$hub_id = NULL;
- $role = DomainController::NODE_NC;
+ $role = Address::NODE_NC;
break;
case 'Hub':
$node = $fields[1];
- $role = DomainController::NODE_HC;
+ $role = Address::NODE_HC;
break;
case 'Pvt':
$node = $fields[1];
- $role = DomainController::NODE_PVT;
+ $role = Address::NODE_PVT;
break;
case 'Hold':
$node = $fields[1];
- $role = DomainController::NODE_HOLD;
+ $role = Address::NODE_HOLD;
break;
case 'Down':
$node = $fields[1];
- $role = DomainController::NODE_DOWN;
+ $role = Address::NODE_DOWN;
break;
case '':
$node = $fields[1];
+ $role = Address::NODE_ACTIVE;
break;
default:
@@ -205,8 +205,6 @@ class NodelistImport implements ShouldQueue
$ao->role = $role;
$ao->hub_id = $hub_id;
- $role = NULL;
-
if ($ao->exists)
Log::debug(sprintf('%s:Processing existing address [%s]',self::LOGKEY,$ao->ftn));
@@ -330,7 +328,7 @@ class NodelistImport implements ShouldQueue
$so->baud = $fields[6];
*/
- if ($method && ($ao->role != DomainController::NODE_PVT)) {
+ if ($method && ($ao->role != Address::NODE_PVT)) {
$so->mailer_type = $method;
$so->mailer_address = $address;
$so->mailer_port = $port;
@@ -352,7 +350,7 @@ class NodelistImport implements ShouldQueue
try {
$so->addresses()->save($ao);
- if ($ao->role == DomainController::NODE_HC)
+ if ($ao->role == Address::NODE_HC)
$hub_id = $ao->id;
$no->addresses()->attach($ao,['role'=>$ao->role]);
@@ -382,4 +380,4 @@ class NodelistImport implements ShouldQueue
Log::info(sprintf('%s:Updated %d records from %d systems',self::LOGKEY,$p,$c));
}
-}
+}
\ No newline at end of file
diff --git a/app/Models/Address.php b/app/Models/Address.php
index 54f5026..16816ff 100644
--- a/app/Models/Address.php
+++ b/app/Models/Address.php
@@ -28,6 +28,17 @@ class Address extends Model
protected $with = ['zone'];
+ public const NODE_ZC = 1<<0; // Zone
+ public const NODE_RC = 1<<1; // Region
+ public const NODE_NC = 1<<2; // Host
+ public const NODE_HC = 1<<3; // Hub
+ public const NODE_ACTIVE = 1<<4; // Node
+ public const NODE_PVT = 1<<5; // Pvt
+ public const NODE_HOLD = 1<<6; // Hold
+ public const NODE_DOWN = 1<<7; // Down
+ public const NODE_POINT = 1<<8; // Point
+ public const NODE_UNKNOWN = 1<<15; // Unknown
+
/* SCOPES */
public function scopeFTNOrder($query)
@@ -52,20 +63,20 @@ class Address extends Model
if (! $this->session('default')) {
switch ($this->role) {
- case DomainController::NODE_ZC:
+ case self::NODE_ZC:
$children = self::select('addresses.*')
->where('zone_id',$this->zone_id);
break;
- case DomainController::NODE_RC:
+ case self::NODE_RC:
$children = self::select('addresses.*')
->where('zone_id',$this->zone_id)
->where('region_id',$this->region_id);
break;
- case DomainController::NODE_NC:
+ case self::NODE_NC:
$children = self::select('addresses.*')
->where('zone_id',$this->zone_id)
->where('region_id',$this->region_id)
@@ -73,16 +84,16 @@ class Address extends Model
break;
- case DomainController::NODE_HC:
+ case self::NODE_HC:
// Identify our children.
$children = self::select('addresses.*')
->where('hub_id',$this->id);
break;
- case DomainController::NODE_UNKNOWN:
- case DomainController::NODE_ACTIVE:
- case DomainController::NODE_POINT:
+ case self::NODE_UNKNOWN:
+ case self::NODE_ACTIVE:
+ case self::NODE_POINT:
// Nodes dont have children, but must return a relationship instance
return $this->hasOne(self::class,NULL,'void');
@@ -158,14 +169,14 @@ class Address extends Model
switch ($this->role) {
// ZCs dont have parents, but we may have a default
- case DomainController::NODE_ZC:
+ case self::NODE_ZC:
if (($x=$this->zone->systems->where('pivot.default',TRUE))->count())
- return $x->first()->match($this->zone)->first();
+ return $x->first()->match($this->zone,255)->first();
else
return NULL;
// RC
- case DomainController::NODE_RC:
+ case self::NODE_RC:
$parent = self::where('zone_id',$this->zone_id)
->where('region_id',0)
->where('host_id',0)
@@ -175,7 +186,7 @@ class Address extends Model
break;
// Hosts
- case DomainController::NODE_NC:
+ case self::NODE_NC:
// See if we have a RC
$parent = self::where('zone_id',$this->zone_id)
->where('region_id',$this->region_id)
@@ -195,9 +206,9 @@ class Address extends Model
break;
// Hubs
- case DomainController::NODE_HC:
+ case self::NODE_HC:
// Normal Nodes
- case DomainController::NODE_ACTIVE:
+ case self::NODE_ACTIVE:
// If we are a child of a hub, then check our hub
$parent = (($this->hub_id)
? self::where('id',$this->hub_id)
@@ -209,9 +220,9 @@ class Address extends Model
break;
- case DomainController::NODE_UNKNOWN:
- case DomainController::NODE_POINT:
- case DomainController::NODE_DOWN:
+ case self::NODE_UNKNOWN:
+ case self::NODE_POINT:
+ case self::NODE_DOWN:
// @todo Points - if the boss is defined, we should return it.
return NULL;
@@ -262,17 +273,17 @@ class Address extends Model
public function getRoleNameAttribute(): string
{
switch ($this->role) {
- case DomainController::NODE_ACTIVE:
- return 'NODE';
- case DomainController::NODE_ZC:
+ case self::NODE_ZC:
return 'ZC';
- case DomainController::NODE_RC:
+ case self::NODE_RC:
return 'RC';
- case DomainController::NODE_NC:
+ case self::NODE_NC:
return 'NC';
- case DomainController::NODE_HC:
+ case self::NODE_HC:
return 'HUB';
- case DomainController::NODE_POINT:
+ case self::NODE_ACTIVE:
+ return 'NODE';
+ case self::NODE_POINT:
return 'POINT';
default:
return '?';
@@ -374,9 +385,11 @@ class Address extends Model
* @param bool $update
* @return Packet|null
*/
- public function getEchomail(bool $update=TRUE): ?Packet
+ public function getEchomail(bool $update=TRUE,Collection $echomail=NULL): ?Packet
{
$pkt = NULL;
+ if ($echomail)
+ return $this->getPacket($echomail);
if (($x=$this->echomailWaiting())
->count())
diff --git a/app/Models/Echomail.php b/app/Models/Echomail.php
index 7e915ab..ff5beac 100644
--- a/app/Models/Echomail.php
+++ b/app/Models/Echomail.php
@@ -69,7 +69,7 @@ final class Echomail extends Model implements Packet
}
// Our address
- $ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone);
+ $ftns = Setup::findOrFail(config('app.id'))->system->match($model->fftn->zone,Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_HOLD);
// Add our address to the seenby;
$model->set_seenby = array_merge($model->set_seenby,$ftns->pluck('id')->toArray());
diff --git a/app/Models/System.php b/app/Models/System.php
index cba4f93..ce07031 100644
--- a/app/Models/System.php
+++ b/app/Models/System.php
@@ -7,8 +7,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
-use App\Http\Controllers\DomainController;
-
class System extends Model
{
use HasFactory;
@@ -103,17 +101,17 @@ class System extends Model
public function full_name(Address $o): string
{
switch ($o->attributes['role']) {
- case DomainController::NODE_ZC;
+ case Address::NODE_ZC;
return sprintf('ZC-%s-%05d',$o->zone->domain->name,$o->zone->zone_id);
- case DomainController::NODE_RC;
+ case Address::NODE_RC;
return sprintf('RC-%s-%05d',$o->zone->domain->name,$o->region_id);
- case DomainController::NODE_NC;
+ case Address::NODE_NC;
return sprintf('NC-%s-%05d',$o->zone->domain->name,$o->host_id);
- case DomainController::NODE_HC;
- case NULL:
+ case Address::NODE_HC;
+ case Address::NODE_ACTIVE;
default:
return $this->name;
}
@@ -121,12 +119,18 @@ class System extends Model
/**
* Return the system's address in the same zone
+ * This function can filter based on the address type needed.
*
* @param Zone $o
+ * @param int $type
* @return Collection
*/
- public function match(Zone $o): Collection
+ public function match(Zone $o,int $type=(Address::NODE_HC|Address::NODE_ACTIVE|Address::NODE_PVT|Address::NODE_POINT)): Collection
{
- return $this->addresses->where('zone_id',$o->id);
+ return $this->addresses
+ ->where('zone_id',$o->id)
+ ->filter(function($item) use ($type) {
+ return $item->role & $type;
+ });
}
}
\ No newline at end of file
diff --git a/database/migrations/2022_01_24_104549_address_role_notnull.php b/database/migrations/2022_01_24_104549_address_role_notnull.php
new file mode 100644
index 0000000..017da4a
--- /dev/null
+++ b/database/migrations/2022_01_24_104549_address_role_notnull.php
@@ -0,0 +1,30 @@
+withTrashed()->update(['role'=>\App\Models\Address::NODE_ACTIVE]);
+ DB::commit();
+ DB::statement("ALTER TABLE addresses ALTER COLUMN role set NOT NULL");
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ DB::statement("ALTER TABLE addresses ALTER COLUMN role drop NOT NULL");
+ }
+}
diff --git a/database/seeders/NodeHierarchy.php b/database/seeders/NodeHierarchy.php
index 9687b8c..7b1e789 100644
--- a/database/seeders/NodeHierarchy.php
+++ b/database/seeders/NodeHierarchy.php
@@ -6,7 +6,6 @@ use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
-use App\Http\Controllers\DomainController;
use App\Models\{Address,Domain,System,Zone};
class NodeHierarchy extends Seeder
@@ -73,7 +72,7 @@ class NodeHierarchy extends Seeder
'node_id'=>0,
'point_id'=>0,
'system_id'=>$so->id,
- 'role'=>DomainController::NODE_ZC,
+ 'role'=>Address::NODE_ZC,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
@@ -90,6 +89,7 @@ class NodeHierarchy extends Seeder
'node_id'=>$nid,
'point_id'=>0,
'system_id'=>$so->id,
+ 'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
@@ -107,7 +107,7 @@ class NodeHierarchy extends Seeder
'node_id'=>0,
'point_id'=>0,
'system_id'=>$so->id,
- 'role'=>DomainController::NODE_RC,
+ 'role'=>Address::NODE_RC,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
@@ -124,6 +124,7 @@ class NodeHierarchy extends Seeder
'node_id'=>$nid,
'point_id'=>0,
'system_id'=>$so->id,
+ 'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
@@ -142,7 +143,7 @@ class NodeHierarchy extends Seeder
'node_id'=>0,
'point_id'=>0,
'system_id'=>$so->id,
- 'role'=>DomainController::NODE_NC,
+ 'role'=>Address::NODE_NC,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
@@ -159,6 +160,7 @@ class NodeHierarchy extends Seeder
'node_id'=>$nid,
'point_id'=>0,
'system_id'=>$so->id,
+ 'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
@@ -175,7 +177,7 @@ class NodeHierarchy extends Seeder
$hub->node_id = $bid;
$hub->point_id = 0;
$hub->system_id = $so->id;
- $hub->role = DomainController::NODE_HC;
+ $hub->role = Address::NODE_HC;
$hub->created_at = Carbon::now();
$hub->updated_at = Carbon::now();
$hub->save();
@@ -194,6 +196,7 @@ class NodeHierarchy extends Seeder
'point_id'=>0,
'system_id'=>$so->id,
'hub_id'=>$hub->id,
+ 'role'=>Address::NODE_ACTIVE,
'created_at'=>Carbon::now(),
'updated_at'=>Carbon::now(),
]);
diff --git a/resources/views/system/addedit.blade.php b/resources/views/system/addedit.blade.php
index 6c12e13..ec64afb 100644
--- a/resources/views/system/addedit.blade.php
+++ b/resources/views/system/addedit.blade.php
@@ -5,7 +5,7 @@
@endsection
@php
-use App\Http\Controllers\DomainController as DC;
+use App\Models\Address as Address;
@endphp
@section('content')
@@ -117,7 +117,7 @@ use App\Http\Controllers\DomainController as DC;
@can('admin',$oo)
{{--
- @if (! $oo->role & (DC::NODE_ZC|DC::NODE_RC|DC::NODE_NC))
+ @if (! $oo->role & (Address::NODE_ZC|Address::NODE_RC|Address::NODE_NC))
@endif
--}}
diff --git a/tests/Feature/PacketTest.php b/tests/Feature/PacketTest.php
index 4145719..515bc5e 100644
--- a/tests/Feature/PacketTest.php
+++ b/tests/Feature/PacketTest.php
@@ -28,9 +28,9 @@ class PacketTest extends TestCase
Zone::unguard();
Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>21,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
- $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>3,'node_id'=>151,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
- $hub = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
- $ao = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>4,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
+ $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>3,'node_id'=>151,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
+ $hub = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
+ $ao = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>1,'node_id'=>4,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_origin.pkt');
@@ -63,7 +63,7 @@ class PacketTest extends TestCase
Zone::unguard();
Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
- $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
+ $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_nomsgid_noorigin.pkt');
@@ -92,7 +92,7 @@ class PacketTest extends TestCase
Zone::unguard();
Address::unguard();
$zo = Zone::firstOrCreate(['zone_id'=>10,'default'=>TRUE,'active'=>TRUE,'domain_id'=>$this->do->id,'system_id'=>$this->so->id]);
- $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'active'=>TRUE,'system_id'=>$this->so->id]);
+ $src = Address::firstOrCreate(['zone_id'=>$zo->id,'region_id'=>0,'host_id'=>999,'node_id'=>1,'point_id'=>0,'role'=>Address::NODE_ACTIVE,'active'=>TRUE,'system_id'=>$this->so->id]);
// This packet has an incorrect zone in the Origin
$f = new File(__DIR__.'/data/test_msgid_origin.pkt');
diff --git a/tests/Feature/RoutingTest.php b/tests/Feature/RoutingTest.php
index 692231e..3dc29ac 100644
--- a/tests/Feature/RoutingTest.php
+++ b/tests/Feature/RoutingTest.php
@@ -2,14 +2,11 @@
namespace Tests\Feature;
-use App\Http\Controllers\DomainController;
-use App\Models\Address;
-use Database\Seeders\NodeHierarchy;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
-use App\Models\Domain;
+use App\Models\{Address,Domain};
class RoutingTest extends TestCase
{
@@ -36,7 +33,7 @@ class RoutingTest extends TestCase
// Pick ZC without any session info - we have 0 children
$ao = Address::findFTN('100:0/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ZC);
+ $this->assertEquals($ao->role,Address::NODE_ZC);
$this->assertCount(0,$ao->children);
$this->assertNull($ao->parent());
@@ -47,15 +44,15 @@ class RoutingTest extends TestCase
// A node's parent should be the ZC
$ao = Address::findFTN('100:10/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_NC);
+ $this->assertEquals($ao->role,Address::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:21/2001.0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
+ $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
// Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_NC);
+ $this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children);
@@ -64,15 +61,15 @@ class RoutingTest extends TestCase
// A node's parent should be the ZC
$ao = Address::findFTN('100:20/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_NC);
+ $this->assertEquals($ao->role,Address::NODE_NC);
$this->assertEquals('100:0/0.0@domain-a',$ao->parent()->ftn);
$ao = Address::findFTN('100:10/2001.0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
+ $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$this->assertEquals('100:10/0.0@domain-a',$ao->parent()->ftn);
// Pick a Node and we have 1 less child
$ao = Address::findFTN('100:21/2001.0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
+ $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/2001.0@domain-a');
$this->assertNULL($ao->children);
@@ -81,7 +78,7 @@ class RoutingTest extends TestCase
// Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:21/1000.0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_HC);
+ $this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:21/1000.0@domain-a');
$this->assertCount(2,$ao->children);
@@ -90,7 +87,7 @@ class RoutingTest extends TestCase
// Define address on a NC and we have 10 less children
$ao = Address::findFTN('100:20/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_NC);
+ $this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:0/0@domain-a');
$this->assertCount(27,$ao->children);
@@ -107,7 +104,7 @@ class RoutingTest extends TestCase
// Pick ZC without any session info - we have 0 children
$ao = Address::findFTN('100:1/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_RC);
+ $this->assertEquals($ao->role,Address::NODE_RC);
$this->assertCount(0,$ao->children);
// Add session info, and we have 51 children
@@ -117,7 +114,7 @@ class RoutingTest extends TestCase
// Pick a NC and we have 10 less children
$ao = Address::findFTN('100:10/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_NC);
+ $this->assertEquals($ao->role,Address::NODE_NC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:10/0@domain-a');
$this->assertCount(9,$ao->children);
@@ -126,7 +123,7 @@ class RoutingTest extends TestCase
// Pick a Node and we have 1 less child
$ao = Address::findFTN('100:11/2001.0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
+ $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/2001.0@domain-a');
$this->assertNULL($ao->children);
@@ -135,7 +132,7 @@ class RoutingTest extends TestCase
// Define address on a HC and we have 3 less children
$ao = Address::findFTN('100:11/1000.0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_HC);
+ $this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:11/1000.0@domain-a');
$this->assertCount(2,$ao->children);
@@ -154,7 +151,7 @@ class RoutingTest extends TestCase
// Pick a HC without any session info - we have 0 children
$ao = Address::findFTN('100:20/0@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_NC);
+ $this->assertEquals($ao->role,Address::NODE_NC);
$this->assertCount(0,$ao->children);
// Add session info, we have 10 children
@@ -164,14 +161,14 @@ class RoutingTest extends TestCase
// Add session info to a hub, we have 3 less children
$ao = Address::findFTN('100:20/2000@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_HC);
+ $this->assertEquals($ao->role,Address::NODE_HC);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(6,$ao->children);
// Add session info to a node, we have 1 less child
$ao = Address::findFTN('100:20/1@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
+ $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/0@domain-a');
$this->assertCount(5,$ao->children);
@@ -188,7 +185,7 @@ class RoutingTest extends TestCase
// Pick a HC without any session info - we have 0 children
$ao = Address::findFTN('100:20/2000@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_HC);
+ $this->assertEquals($ao->role,Address::NODE_HC);
$this->assertCount(0,$ao->children);
// Add session info, we have 2 children
@@ -209,7 +206,7 @@ class RoutingTest extends TestCase
// Node with session details still doesnt have any children
$ao = Address::findFTN('100:20/2001@domain-a');
- $this->assertEquals($ao->role,DomainController::NODE_ACTIVE);
+ $this->assertEquals($ao->role,Address::NODE_ACTIVE);
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:20/2001@domain-a');
$this->assertNULL($ao->children);