2021-07-15 14:54:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
/**
|
|
|
|
* Our testing heirarchy.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-07-15 14:54:23 +00:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
use App\Models\{Address,Domain,Setup,System,Zone};
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2023-10-17 12:19:28 +00:00
|
|
|
class TestNodeHierarchy extends Seeder
|
2021-07-15 14:54:23 +00:00
|
|
|
{
|
2024-11-25 02:46:16 +00:00
|
|
|
public const DEBUG = TRUE;
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2021-07-15 14:54:23 +00:00
|
|
|
public function run()
|
|
|
|
{
|
2024-11-25 02:46:16 +00:00
|
|
|
foreach (['a','b','c','d','e','f'] as $domain) {
|
|
|
|
DB::table('domains')
|
|
|
|
->insert([
|
|
|
|
'name'=>$domain,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'public'=>TRUE,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2024-11-08 12:31:21 +00:00
|
|
|
$do = Domain::where('name',$domain)->sole();
|
2022-11-11 11:57:40 +00:00
|
|
|
$this->hierarchy($do,100);
|
|
|
|
$this->hierarchy($do,101);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
2023-11-21 23:40:15 +00:00
|
|
|
|
|
|
|
// Configure my addresses
|
|
|
|
$so = Setup::findOrFail(config('app.id'));
|
2024-11-25 02:46:16 +00:00
|
|
|
|
|
|
|
// ZC 100:0/0@a
|
2023-11-21 23:40:15 +00:00
|
|
|
$ao = Address::findFTN('100:0/0@a');
|
2024-11-25 02:46:16 +00:00
|
|
|
$ao->system_id = $so->system_id;
|
|
|
|
$ao->save();
|
|
|
|
|
|
|
|
// RC 100:1/0@b
|
|
|
|
$ao = Address::findFTN('100:1/0@b');
|
|
|
|
$ao->system_id = $so->system_id;
|
|
|
|
$ao->save();
|
|
|
|
|
|
|
|
// NC 100:20/0@c
|
|
|
|
$ao = Address::findFTN('100:20/0@c');
|
|
|
|
$ao->system_id = $so->system_id;
|
|
|
|
$ao->save();
|
|
|
|
|
|
|
|
// HUB 100:30/100@d
|
|
|
|
$ao = Address::findFTN('100:30/100@d');
|
|
|
|
$ao->system_id = $so->system_id;
|
|
|
|
$ao->save();
|
|
|
|
|
|
|
|
// NODE 100:40/101@e
|
|
|
|
$ao = Address::findFTN('100:40/101@e');
|
|
|
|
$ao->system_id = $so->system_id;
|
|
|
|
$ao->save();
|
|
|
|
|
|
|
|
// POINT 100:50/101.3277@f
|
|
|
|
$ao = Address::createFTN('100:50/101.3277@f',$so->system);
|
|
|
|
|
|
|
|
$so->system->name = 'Clearing Houz TEST';
|
|
|
|
$so->system->address = 'localhost';
|
|
|
|
$so->system->save();
|
2023-11-21 23:40:15 +00:00
|
|
|
|
|
|
|
// 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(),
|
|
|
|
]);
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function hierarchy(Domain $domain,int $zoneid)
|
|
|
|
{
|
2024-11-25 02:46:16 +00:00
|
|
|
$levels = [1,2,3,4,5];
|
2023-11-21 23:40:15 +00:00
|
|
|
$hubnodes = [-2,-1,+1,+2,+3];
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2023-11-21 23:40:15 +00:00
|
|
|
$so = $this->system(sprintf('ZC %s-%s',$domain->name,$zoneid));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('zones')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zoneid,
|
|
|
|
'active'=>TRUE,
|
2023-11-21 23:40:15 +00:00
|
|
|
'default'=>$domain->name === 'a',
|
2021-07-15 14:54:23 +00:00
|
|
|
'notes'=>sprintf('Zone: %03d:0/0.0@%s',$zoneid,$domain->name),
|
|
|
|
'domain_id'=>$domain->id,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2024-11-08 12:31:21 +00:00
|
|
|
$zo = Zone::where('zone_id',$zoneid)->where('domain_id',$domain->id)->sole();
|
2024-11-25 02:46:16 +00:00
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
2024-11-25 02:46:16 +00:00
|
|
|
printf("- ZC %d:%d/%d.%d@%s\n",$zo->zone_id,0,0,0,$domain->name);
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
$region_id = 0;
|
|
|
|
// ZC Address
|
2021-07-26 11:21:58 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$region_id,
|
2021-07-26 11:21:58 +00:00
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
2021-07-15 14:54:23 +00:00
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
// ZC Nodes
|
2024-11-25 02:46:16 +00:00
|
|
|
foreach ($hubnodes as $hnid) {
|
|
|
|
$host_id = $region_id*100+$hnid+3;
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
2024-11-25 02:46:16 +00:00
|
|
|
printf(" - NODE %d:%d/%d.%d@%s\n",$zo->zone_id,$region_id,$host_id,0,$domain->name);
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
$so = $this->system(sprintf('ZC Node 0/%d',$host_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$region_id,
|
|
|
|
'node_id'=>$host_id,
|
2021-07-15 14:54:23 +00:00
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
// RC
|
|
|
|
foreach ($levels as $region_id) {
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
2024-11-25 02:46:16 +00:00
|
|
|
printf(" - RC %d:%d/%d.%d@%s\n",$zo->zone_id,$region_id,0,0,$domain->name);
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
$so = $this->system(sprintf('RC %03d:%03d/%03d.0@%s',$zoneid,$region_id,0,$domain->name));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$region_id,
|
2021-07-15 14:54:23 +00:00
|
|
|
'node_id'=>0,
|
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
// RC Nodes
|
2024-11-25 02:46:16 +00:00
|
|
|
foreach ($hubnodes as $hnid) {
|
|
|
|
$host_id = $hnid+3;
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
2024-11-25 02:46:16 +00:00
|
|
|
printf(" - NODE %d:%d/%d.%d@%s\n",$zo->zone_id,$region_id,$host_id,0,$domain->name);
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
$so = $this->system(sprintf('RC Node %d/%d',$region_id,$host_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$region_id,
|
|
|
|
'node_id'=>$host_id,
|
2021-07-15 14:54:23 +00:00
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
// NC
|
|
|
|
foreach ($levels as $ncid) {
|
|
|
|
$net_id = $region_id*10+$ncid-1;
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
2024-11-25 02:46:16 +00:00
|
|
|
printf(" - NC %d:%d/%d.%d@%s\n",$zo->zone_id,$net_id,0,0,$domain->name);
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
$so = $this->system(sprintf('NC %d:%d/0 (R%d)',$zo->zone_id,$net_id,$region_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$net_id,
|
2023-12-13 01:13:47 +00:00
|
|
|
'node_id'=>0,
|
2021-07-15 14:54:23 +00:00
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
// NC Nodes
|
|
|
|
foreach ($hubnodes as $hnid) {
|
|
|
|
$host_id = $hnid+3;
|
|
|
|
|
2022-11-19 13:19:09 +00:00
|
|
|
if (self::DEBUG)
|
2024-11-25 02:46:16 +00:00
|
|
|
printf(" - NODE %d:%d/%d.%d@%s\n",$zo->zone_id,$net_id,$host_id,0,$domain->name);
|
2022-11-19 13:19:09 +00:00
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
$so = $this->system(sprintf('NC Node %d/%d (R%d)',$net_id,$host_id,$region_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$net_id,
|
|
|
|
'node_id'=>$host_id,
|
2021-07-15 14:54:23 +00:00
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hubs
|
2024-11-25 02:46:16 +00:00
|
|
|
foreach ($levels as $hbid) {
|
|
|
|
$host_id = $hbid*100;
|
|
|
|
|
|
|
|
if (self::DEBUG)
|
|
|
|
printf(" - HUB %d:%d/%d.%d@%s\n",$zo->zone_id,$net_id,$host_id,0,$domain->name);
|
|
|
|
|
|
|
|
$so = $this->system(sprintf('HUB %d/%d (R%d)',$net_id,$host_id,$region_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
$hub = new Address;
|
|
|
|
$hub->zone_id = $zo->id;
|
|
|
|
$hub->active = TRUE;
|
2024-11-25 02:46:16 +00:00
|
|
|
$hub->region_id = $region_id;
|
|
|
|
$hub->host_id = $net_id;
|
|
|
|
$hub->node_id = $host_id;
|
2021-07-15 14:54:23 +00:00
|
|
|
$hub->point_id = 0;
|
|
|
|
$hub->system_id = $so->id;
|
|
|
|
$hub->created_at = Carbon::now();
|
|
|
|
$hub->updated_at = Carbon::now();
|
|
|
|
$hub->save();
|
|
|
|
|
2024-11-25 02:46:16 +00:00
|
|
|
// HUB Nodes
|
2021-07-15 14:54:23 +00:00
|
|
|
foreach ($hubnodes as $nid) {
|
2024-11-25 02:46:16 +00:00
|
|
|
$host_id = $hub->node_id+$nid;
|
|
|
|
|
|
|
|
if (self::DEBUG)
|
|
|
|
printf(" - NODE %d:%d/%d.%d@%s\n",$zo->zone_id,$net_id,$host_id,0,$domain->name);
|
|
|
|
|
|
|
|
$so = $this->system(sprintf('Hub Node %d/%d (R%d/H%d)',$net_id,$host_id,$region_id,$hub->node_id));
|
2021-07-15 14:54:23 +00:00
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
2024-11-25 02:46:16 +00:00
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$net_id,
|
|
|
|
'node_id'=>$host_id,
|
2021-07-15 14:54:23 +00:00
|
|
|
'point_id'=>0,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'hub_id'=>$hub->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
2024-11-25 02:46:16 +00:00
|
|
|
|
|
|
|
foreach ($hubnodes as $nid) {
|
|
|
|
$point_id = $nid+3;
|
|
|
|
|
|
|
|
if (self::DEBUG)
|
|
|
|
printf(" - POINT %d:%d/%d.%d@%s\n",$zo->zone_id,$net_id,$host_id,$point_id,$domain->name);
|
|
|
|
|
|
|
|
$so = $this->system(sprintf('Node Point %d/%d.%d (R%d/H%d)',$net_id,$host_id,$point_id,$region_id,$hub->node_id));
|
|
|
|
DB::table('addresses')
|
|
|
|
->insert([
|
|
|
|
'zone_id'=>$zo->id,
|
|
|
|
'active'=>TRUE,
|
|
|
|
'region_id'=>$region_id,
|
|
|
|
'host_id'=>$net_id,
|
|
|
|
'node_id'=>$host_id,
|
|
|
|
'point_id'=>$point_id,
|
|
|
|
'system_id'=>$so->id,
|
|
|
|
'created_at'=>Carbon::now(),
|
|
|
|
'updated_at'=>Carbon::now(),
|
|
|
|
]);
|
|
|
|
}
|
2021-07-15 14:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function system(string $name): System
|
|
|
|
{
|
|
|
|
$o = new System;
|
|
|
|
$o->name = $name;
|
2023-11-21 23:40:15 +00:00
|
|
|
$o->sysop = 'Sysop:'.$name;
|
|
|
|
$o->location = 'Location:'.$name;
|
2021-07-15 14:54:23 +00:00
|
|
|
$o->active = TRUE;
|
|
|
|
$o->created_at = Carbon::now();
|
|
|
|
$o->updated_at = Carbon::now();
|
2024-11-25 02:46:16 +00:00
|
|
|
$o->address = 'myhostname';
|
2021-07-15 14:54:23 +00:00
|
|
|
$o->save();
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
2024-11-25 02:46:16 +00:00
|
|
|
}
|