## 4 Proposed Architecture
### Implementation Phase
The LDP daemon source code is located in the ldpd directory of the FRR package. The ldpd code is organized into several files, including the following:  
* ldpd.c: This file contains the main function for the LDP daemon. It sets up the LDP protocol, initializes the LDP database, and starts the LDP event loop. * ldp_interface.c: This file contains the code for managing LDP interfaces. It handles interface events, such as interface up/down, and enables LDP on active MPLS interfaces. * ldp_l2 vpn.c: This file contains the code for managing Layer 2 VPNs. It handles the creation, deletion, and updating of PWs, and also manages the L2 VPN database. * ldp_ldp.c: This file contains the code for managing LDP sessions and exchanging label information with other LDP routers. It implements the LDP protocol and handles LDP messages. * ldp_label.c: This file contains the code for managing LDP labels. It handles label distribution, label assignment, and label retention. Overall, the ldpd directory in the FRR package contains the implementation code for the LDP daemon, which is responsible for managing the LDP protocol and establishing LSPs in an MPLS network. By activating L2 vpn in the LDP_Virtual teletype (VYY)_Configure file, the LDP daemon is instructed to enable support for Layer 2 VPNs and to manage PWs. The implementation code is written in the C programming language and is organized into several files based on their functionality. In the following, using LDP_Virtual teletype (VYY)_Configure file, and by activating L2 vpn [56], the following sub-functions are called, which are summarized as follows:Here, line 3 in Algorithm 1, _PseudoWireType()_ is responsible for specifying the PW type based on the type given by the network administrator. The PW type is stored with a special code number Ethernet or Ethernet_tagged. _DedicatedPseudoWire()_--the interface and PW considered by the admin must be assigned. It must first be determined whether the interface and PW expressed have been used before. This is done by searching for the interface name in the existing l2 vpn. If the PW ID or LSR ID was not previously used by another l2 vpn, this PW will be removed from the passive PW list and assigned to the relevant l2 vpn. _PwNeighborAddr()_--the address of the router that is neighboring the current router by PW must be assigned. The family from which the address is selected (ipv4 or ipv6) and the neighbor's router address are given by the admin. Because these data are set by the admin, their flag is stored as static. _PwNeighborId()_--the router ID assigned to the current router by the PW is assigned. At the end line of Algorithm 1, _PwIdAssig()_, the router's ID, which is dedicated to PW, is assigned. ```
0: Enable L2 vpn
1:Input:[Int pw_type; struct l2 vpn_pw *pw; union ldpd_addr addr; struct in_addr lsr_id]
2:pw = l2 vpn_pw_find(l2 vpn, InterfaceName);
3:Call sub-Function_1 PseudoWireType (pw_type);
4:Call sub-Function_2 DedicatedPseudoWire ();
5:Call sub-Function_3 PwNeighborAddr (addr);
6:Call sub-Function_4 PwNeighborId (addr, Id);
7:Call sub-Function_5 PwIdAssig (pwid);
```  
**Algorithm 1** LDP_12 vpn_PWtype (0  
In the l2 vpn_Configure file, the following sub-functions are used inside the l2 vpn function to perform the searches or changes needed to attach PW. Here, Line 2 of Algorithm 2, _PwNew()_ creates PW given by the admin. _PwFind(pw, InterfaceName)_ searches PW given by the admin in the corresponding tree. If there is such a PW to assign, we can activate it in the next steps if it is disabled and is assigned to l2 vpn. In the following two functions, _PwFindActive(pw)_ and _PwFindinActive(pw)_, the active or inactive state of the given PW is specified. _PwUpdateInfo(pw)_--in the event of a new change, the index will be updated. _PwInit(pw, fcc)_ is called in ldpd(). When the LDE_ENGINE process is considered to run, PW information is transferred to the kernel. By calling _PwExit(pw)_ in ldpd() function, the necessary updates about PW will be made.