- $self->_dellist('dxchan', $dxchan);
- $neighbour->_dellist('dxchan', $dxchan);
- return $self->is_empty('dxchan') ? ($self) : ();
+ $neighbour->_dellist('dxchan', $dxchan) if $dxchan;
+ return $neighbour->is_empty('dxchan') ? ($neighbour) : ();
+}
+
+sub remove_route
+{
+ my ($self, $neighbour, $dxchan) = @_;
+
+ # cut the dxchan link
+ # cut the node link
+ my @rout;
+ push @rout, $self->unlink_node($neighbour, $dxchan);
+ dbg("Orphanning $neighbour->{call}") if isdbg('routelow');
+
+ # then run down the tree removing this dxchan link from
+ # all the referenced nodes that use this interface
+ my %visited;
+ my @in = map { Route::Node::get($_) } $neighbour->nodes;
+ foreach my $r (@in) {
+ next unless $r;
+ next if $visited{$r->call};
+ my ($o) = $r->del_dxchan($self);
+ if ($o) {
+ dbg("Orphanning $_->{call}") if isdbg('routelow');
+ push @rout, $o;
+ }
+ push @in, map{ Route::Node::get($_) } $r->nodes;
+ $visited{$r->call} = $r;
+ }
+
+ # in @rout there should be a list of orphaned (in dxchan terms)
+ # nodes. Now go thru and make sure that all their links are
+ # broken (they should be, but this is to check).
+
+ foreach my $r (@rout) {
+ my @nodes = map { Route::Node::get($_)} $r->nodes;
+ for (@nodes) {
+ next unless $_;
+ dbg("Orphaned node $_->{call}: breaking link to $_->{call}") if isdbg('routelow');
+ $r->unlink_node($_);
+ }
+ }
+ return @rout;