Sunday 31 January 2021

Master Network Automation with Python for Network Engineers using SSH, Paramiko, Netmiko, Telnet or Serial Connections

Network automation is the process of automating network configuration and management tasks using software tools and scripts. Automation can help network administrators reduce manual errors, improve network performance, and increase efficiency.

To automate network tasks, you need to be familiar with various networking protocols and programming languages. In this response, I will focus on the SSH, Paramiko, Netmiko, Telnet, and serial connections.

SSH:

SSH (Secure Shell) is a network protocol that provides secure access to remote devices. It is widely used in network automation to connect to network devices and execute commands remotely. Here's an example of how to use SSH with Python:

Read more »

Labels:

Saturday 8 August 2020

Perl DB Connection Tutorial with Different databases

 Perl provides support for connecting and interacting with a variety of databases. Here are some examples of connecting to different databases using Perl:

Method 1: Connecting to MySQL using DBI

The Perl DBI (Database Interface) module provides a consistent interface for connecting to and interacting with different databases. Here's an example of connecting to a MySQL database using DBI:

Read more »

Labels:

Sunday 1 December 2019

perl piped open - reading data from a system process?

Perl Piped Open:

open function is very useful for reading or writing the data files on the system and apart from this file processing we can use pipe symbol for getting data from a system process or sending the data to a system process can be achieved.   lets try this now,


Read more »

Labels: , , , , , ,

Monday 4 November 2019

perl read file - 15 ways

Method 1:


open(FH,'<file.txt') or die "Cant open file $!";

print FH;

close(FH);

Read more »

Labels:

Friday 2 October 2020

write 1000 uniq perl interview questions and answers to master in perl - part1

  1. Q: In Perl, what does the sigil $_ represent?

    A: In Perl, the sigil $_ represents the default argument to a subroutine. It is a global variable that is set automatically by Perl whenever a subroutine is called.

  2. Q: In Perl, what does the backslash \ do in front of a variable name?

    A: In Perl, the backslash \ in front of a variable name is used to force a string interpretation of the variable, rather than a numeric interpretation. This can be useful when working with non-numeric variables, or when you want to avoid potential side effects caused by Perl's built-in operations on numbers

Read more »

Labels:

Saturday 2 November 2019

perl insert new line at beginning of existing data file

Method 1:

1.perl -pi -e 'print "perl one liner is added" if $. == 1'  file.txt

Method 2:

open my $file1,  '<',  $file1.txt;
open my $file2, '>', "$file2.txt";

print $file2 "perl one liner is added";

while( <$file1> ) {
    print $file2 $_;
}
close $file2;
close $file1;

Method 3:

echo "perl one liner is added" | perl -0 -i -pe 'BEGIN {$input = <STDIN>}; print $input' file.txt

Method 4:

open(M,"<","file1.txt");
@m = <M>;
close(M);
open(M,">","file2.txt");
unshift (@m,"Perl Coder is always magic\n");
print M @m;
close(M);


kaavannan perl blogspot

Labels: , , , ,

Tuesday 1 February 2022

Python Asyncio: Building High-Performance Web Apps with Asynchronous Programming

As the demand for web applications continues to grow, developers are constantly seeking ways to improve their performance and scalability. One approach to achieve this is through asynchronous programming, which allows applications to handle multiple tasks simultaneously without blocking the main thread. Python's asyncio library provides a powerful toolset for implementing asynchronous programming, and in this article, we will explore its features and how to leverage them to build high-performance web applications.

What is asyncio?

Asyncio is a Python library for asynchronous programming that was introduced in Python 3.4. It allows developers to write concurrent code in a simple and elegant way, without the complexity of traditional multi-threaded programming. Asyncio is built on top of coroutines, which are lightweight subroutines that can be suspended and resumed during their execution. This makes it possible to execute multiple tasks concurrently without blocking the main thread.

Read more »

Labels: , ,

Thursday 9 June 2022

perl vlsi program for Design Rule Checker


#!/usr/bin/perl


use strict;

use warnings;


# Read design rules from file

my $rule_file = shift;

open my $fh, "<", $rule_file or die "Error: Could not open rule file: $!\n";

my $rules = do { local $/; <$fh> };

close $fh;


# Read layout design from file

my $design_file = shift;

open $fh, "<", $design_file or die "Error: Could not open design file: $!\n";

my $design = do { local $/; <$fh> };

close $fh;


# Check design against rules

my $errors = 0;

foreach my $rule (split /\n/, $rules) {

    chomp $rule;

    $rule =~ s/^\s+|\s+$//g;

    next if $rule =~ /^#/;

    if ($rule =~ /^(\S+)\s+(.*?)$/) {

        my $rule_type = $1;

        my $rule_pattern = $2;

        if ($rule_type eq "layer") {

            # Check for correct layer usage

            my @matches = $design =~ /$rule_pattern/g;

            if (@matches) {

                print "Error: Found $rule_type \"$rule_pattern\" in layout design\n";

                $errors++;

            }

        }

        elsif ($rule_type eq "spacing") {

            # Check for minimum spacing between objects

            my $spacing = $rule_pattern;

            my $pattern = "\\s*[Mm]\\s*\\(\\s*\\d+\\s*\\)\\s*[Mm]"; # matches two adjacent metal layers

            my @matches = $design =~ /$pattern/g;

            foreach my $match (@matches) {

                if ($match =~ /($pattern){0,$spacing-1}/) {

                    print "Error: Found adjacent objects with spacing less than $spacing in layout design\n";

                    $errors++;

                    last; # exit loop once an error is found

                }

            }

        }

        else {

            print "Warning: Unknown design rule type \"$rule_type\"\n";

        }

    }

}


if ($errors == 0) {

    print "Design passed all design rule checks.\n";

}

else {

    print "Design failed $errors design rule checks.\n";

}


 it will print out any errors or warnings that are detected during the design rule checking process. If there are no errors, it will print a message indicating that the design has passed all design rule checks.

design rules are specified in a file, where each rule is a line that starts with a rule type ("layer" or "spacing"), followed by a rule pattern that specifies the layer or spacing requirements. 

For example:

# Design rules file

layer M1

layer M2

spacing 3 

run it from the command line and specify the design rules file and layout design file as arguments. For example:

$ perl design_rule_checker.pl design_rules.txt layout_design.gds

 design_rule_checker.pl is the name of the Perl program, design_rules.txt is the name of the file containing the design rules, and layout_design.gds is the name of the layout design file to be checked.

example design rules file that checks for some common design rule violations:

# Design Rules File



# Define spacing rules

spacing metal1_metal1 0.12

spacing metal1_via1 0.12

spacing metal2_metal2 0.15

spacing metal2_via2 0.15



# Define width rules

width metal1 0.25

width metal2 0.4



# Define enclosure rules

enclosure metal1_via1 0.1

enclosure metal2_via2 0.2

The spacing rule checks the minimum distance between two layers, while the width rule checks the minimum width of a metal layer. The enclosure rule checks the minimum amount of metal surrounding a via.

The metal1_metal1, metal1_via1, metal2_metal2, and metal2_via2 keywords are the layer types that the rules apply to. These keywords should match the layer names used in the layout design file.

To use this design rules file with the design_rule_checker.pl program, you would specify the filename as the first argument when running the program:

$ perl design_rule_checker.pl design_rules.txt layout_design.gds


#!/usr/bin/perl
use strict;
use warnings;

# Read in the design rules file
my $rules_file = $ARGV[0];
open(my $rules_fh, '<', $rules_file) or die "Could not open $rules_file: $!";

# Parse the design rules and store them in a hash
my %rules;
while (my $line = <$rules_fh>) {
    chomp $line;
    my ($rule_type, $layer_type, $value) = split ' ', $line;
    $rules{$rule_type}{$layer_type} = $value;
}
close $rules_fh;

# Read in the layout design file
my $layout_file = $ARGV[1];
open(my $layout_fh, '<', $layout_file) or die "Could not open $layout_file: $!";

# Parse the layout design and check against the design rules
my $line_number = 0;
while (my $line = <$layout_fh>) {
    $line_number++;
    chomp $line;

    # Check for minimum spacing violations
    if ($line =~ /^S\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/) {
        my ($type1, $layer1, $type2, $layer2, $distance, $extension) = ($1, $2, $3, $4, $5, $6);
        if ($rules{'spacing'}{"$layer1\_$layer2"} && $distance < $rules{'spacing'}{"$layer1\_$layer2"}) {
            print "Error: Minimum spacing violation on line $line_number\n";
        }
    }

    # Check for minimum width violations
    if ($line =~ /^W\s(\S+)\s(\S+)/) {
        my ($layer, $width) = ($1, $2);
        if ($rules{'width'}{$layer} && $width < $rules{'width'}{$layer}) {
            print "Error: Minimum width violation on line $line_number\n";
        }
    }

    # Check for minimum enclosure violations
    if ($line =~ /^E\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/) {
        my ($type1, $layer1, $type2, $layer2, $distance) = ($1, $2, $3, $4, $5);
        if ($rules{'enclosure'}{"$layer1\_$layer2"} && $distance < $rules{'enclosure'}{"$layer1\_$layer2"}) {
            print "Error: Minimum enclosure violation on line $line_number\n";
        }
    }
}
close $layout_fh;

The design rules file should contain the following information:

  • Minimum spacing between two layers
  • Minimum width for a layer
  • Minimum enclosure of one layer around another layer

The layout design file should contain the following information for each component:

  • Type of component
  • Layer of component
  • Position of component
  • Dimensions of component

The design_rule_checker.pl program will output an error message for any violations of the design rules, indicating the type of violation and the line number in the layout design file where the violation occurred.


Labels: