Rework TIC processing and added test cases
This commit is contained in:
@@ -6,11 +6,11 @@ use Carbon\Carbon;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Models\{Address,Domain,System,Zone};
|
||||
use App\Models\{Address, Domain, Setup, System, Zone};
|
||||
|
||||
class TestNodeHierarchy extends Seeder
|
||||
{
|
||||
public const DEBUG=TRUE;
|
||||
public const DEBUG=FALSE;
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
@@ -21,7 +21,7 @@ class TestNodeHierarchy extends Seeder
|
||||
{
|
||||
DB::table('domains')
|
||||
->insert([
|
||||
'name'=>'domain-a',
|
||||
'name'=>'a',
|
||||
'active'=>TRUE,
|
||||
'public'=>TRUE,
|
||||
'created_at'=>Carbon::now(),
|
||||
@@ -30,33 +30,53 @@ class TestNodeHierarchy extends Seeder
|
||||
|
||||
DB::table('domains')
|
||||
->insert([
|
||||
'name'=>'domain-b',
|
||||
'name'=>'b',
|
||||
'active'=>TRUE,
|
||||
'public'=>TRUE,
|
||||
'created_at'=>Carbon::now(),
|
||||
'updated_at'=>Carbon::now(),
|
||||
]);
|
||||
|
||||
foreach (['domain-a','domain-b'] as $domain) {
|
||||
foreach (['a','b'] as $domain) {
|
||||
$do = Domain::where('name',$domain)->singleOrFail();
|
||||
$this->hierarchy($do,100);
|
||||
$this->hierarchy($do,101);
|
||||
}
|
||||
|
||||
// Configure my addresses
|
||||
$so = Setup::findOrFail(config('app.id'));
|
||||
$ao = Address::findFTN('100:0/0@a');
|
||||
$so->system_id = $ao->system_id;
|
||||
$so->save();
|
||||
|
||||
// Add file area
|
||||
DB::table('fileareas')
|
||||
->insert([
|
||||
'name'=>'FILE_AREA',
|
||||
'description'=>'Testing File Area',
|
||||
'active'=>TRUE,
|
||||
'show'=>TRUE,
|
||||
'notes'=>'File area for testing',
|
||||
'domain_id'=>$ao->zone->domain_id,
|
||||
'security'=>1,
|
||||
'created_at'=>Carbon::now(),
|
||||
'updated_at'=>Carbon::now(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function hierarchy(Domain $domain,int $zoneid)
|
||||
{
|
||||
$regions = [1,2];
|
||||
//$hosts = [20,30];
|
||||
$hubs = [1000,2000];
|
||||
$nodes = [1,2,3];
|
||||
$hubnodes = [-1,+1];
|
||||
$hosts = [1,2,3,4,5];
|
||||
$hubs = [10,20,30,40,50];
|
||||
$nodes = [100,200,300,400,500];
|
||||
$hubnodes = [-2,-1,+1,+2,+3];
|
||||
|
||||
$so = $this->system('ZC '.$domain->id);
|
||||
$so = $this->system(sprintf('ZC %s-%s',$domain->name,$zoneid));
|
||||
DB::table('zones')
|
||||
->insert([
|
||||
'zone_id'=>$zoneid,
|
||||
'active'=>TRUE,
|
||||
'default'=>$domain->name === 'a',
|
||||
'notes'=>sprintf('Zone: %03d:0/0.0@%s',$zoneid,$domain->name),
|
||||
'domain_id'=>$domain->id,
|
||||
'system_id'=>$so->id,
|
||||
@@ -68,10 +88,12 @@ class TestNodeHierarchy extends Seeder
|
||||
if (self::DEBUG)
|
||||
dump(['zo'=>$zo->zone_id,'rid'=>0,'hid'=>0,'nid'=>0]);
|
||||
|
||||
// ZC
|
||||
DB::table('addresses')
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>0,
|
||||
'host_id'=>0,
|
||||
'node_id'=>0,
|
||||
@@ -87,11 +109,12 @@ class TestNodeHierarchy extends Seeder
|
||||
if (self::DEBUG)
|
||||
dump(['rid'=>$zo->zone_id,'hid'=>$zo->zone_id,'nid'=>$nid]);
|
||||
|
||||
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (ZC Node)',$zoneid,0,$nid,$domain->name));
|
||||
$so = $this->system(sprintf('ZC Node 0/%d',$nid));
|
||||
DB::table('addresses')
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>0,
|
||||
'host_id'=>0,
|
||||
'node_id'=>$nid,
|
||||
@@ -107,7 +130,7 @@ class TestNodeHierarchy extends Seeder
|
||||
dump(['end'=>'nodes top']);
|
||||
|
||||
// Regions
|
||||
foreach ($regions as $rid) {
|
||||
foreach ($hosts as $rid) {
|
||||
$hostid = $rid;
|
||||
if (self::DEBUG)
|
||||
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
|
||||
@@ -117,6 +140,7 @@ class TestNodeHierarchy extends Seeder
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>$rid,
|
||||
'host_id'=>$rid,
|
||||
'node_id'=>0,
|
||||
@@ -132,11 +156,12 @@ class TestNodeHierarchy extends Seeder
|
||||
if (self::DEBUG)
|
||||
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
|
||||
|
||||
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (RC Node)',$zoneid,$rid,$nid,$domain->name));
|
||||
$so = $this->system(sprintf('RC Node %d/%d',$rid,$nid));
|
||||
DB::table('addresses')
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>$rid,
|
||||
'host_id'=>$rid,
|
||||
'node_id'=>$nid,
|
||||
@@ -147,20 +172,22 @@ class TestNodeHierarchy extends Seeder
|
||||
'updated_at'=>Carbon::now(),
|
||||
]);
|
||||
}
|
||||
dump(['end'=>'NODES regions']);
|
||||
if (self::DEBUG)
|
||||
dump(['end'=>'NODES regions']);
|
||||
|
||||
// Hosts
|
||||
foreach ($regions as $rrid) {
|
||||
foreach ($hosts as $rrid) {
|
||||
$hostid = $rid*10+$rrid-1;
|
||||
if (self::DEBUG)
|
||||
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>0]);
|
||||
|
||||
$so = $this->system(sprintf('Host %03d:%03d/0.0@%s (Region %03d)',$zoneid,$hostid,$domain->name,$rid));
|
||||
$so = $this->system(sprintf('Host %d:%d/0 (R%d)',$zoneid,$hostid,$rid));
|
||||
|
||||
DB::table('addresses')
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>$rid,
|
||||
'host_id'=>$hostid,
|
||||
'node_id'=>0,
|
||||
@@ -176,11 +203,12 @@ class TestNodeHierarchy extends Seeder
|
||||
if (self::DEBUG)
|
||||
dump(['rid'=>$rid,'hid'=>$hostid,'nid'=>$nid]);
|
||||
|
||||
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (Region %03d) - Host Node',$zoneid,$hostid,$nid,$domain->name,$rid));
|
||||
$so = $this->system(sprintf('Host Node %d/%d (R%d)',$hostid,$nid,$rid));
|
||||
DB::table('addresses')
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>$rid,
|
||||
'host_id'=>$hostid,
|
||||
'node_id'=>$nid,
|
||||
@@ -194,7 +222,7 @@ class TestNodeHierarchy extends Seeder
|
||||
|
||||
// Hubs
|
||||
foreach ($hubs as $bid) {
|
||||
$so = $this->system(sprintf('Hub %03d:%03d/%03d.0@%s (Region %03d)',$zoneid,$hostid,$bid,$domain->name,$rid));
|
||||
$so = $this->system(sprintf('HUB %d/%d (R%d)',$hostid,$bid,$rid));
|
||||
$hub = new Address;
|
||||
$hub->zone_id = $zo->id;
|
||||
$hub->active = TRUE;
|
||||
@@ -211,11 +239,12 @@ class TestNodeHierarchy extends Seeder
|
||||
// Nodes
|
||||
foreach ($hubnodes as $nid) {
|
||||
$nodeid = $bid+$nid;
|
||||
$so = $this->system(sprintf('Node %03d:%03d/%03d.0@%s (Region %03d) - Hub Node',$zoneid,$hostid,$nodeid,$domain->name,$rid));
|
||||
$so = $this->system(sprintf('Hub Node %d/%d (R%d/H%d)',$hostid,$nodeid,$rid,$hub->node_id));
|
||||
DB::table('addresses')
|
||||
->insert([
|
||||
'zone_id'=>$zo->id,
|
||||
'active'=>TRUE,
|
||||
'validated'=>TRUE,
|
||||
'region_id'=>$rid,
|
||||
'host_id'=>$hostid,
|
||||
'node_id'=>$nodeid,
|
||||
@@ -229,18 +258,20 @@ class TestNodeHierarchy extends Seeder
|
||||
}
|
||||
}
|
||||
}
|
||||
dump(['end'=>'NODES normal']);
|
||||
if (self::DEBUG)
|
||||
dump(['end'=>'NODES normal']);
|
||||
}
|
||||
|
||||
dump(['end'=>'heirarchy']);
|
||||
if (self::DEBUG)
|
||||
dump(['end'=>'heirarchy']);
|
||||
}
|
||||
|
||||
private function system(string $name): System
|
||||
{
|
||||
$o = new System;
|
||||
$o->name = $name;
|
||||
$o->sysop = 'Mr Sysop of '.$name;
|
||||
$o->location = 'Some place for '.$name;
|
||||
$o->sysop = 'Sysop:'.$name;
|
||||
$o->location = 'Location:'.$name;
|
||||
$o->active = TRUE;
|
||||
$o->created_at = Carbon::now();
|
||||
$o->updated_at = Carbon::now();
|
||||
|
Reference in New Issue
Block a user