+/*******************************************************************
+ *
+ * @brief this function includes all the functionalities of client side
+ * like binding the client side socket and connecting to the server
+ *
+ * @details
+ *
+ * Function : startL1AsClient
+ *
+ * Functionality: this function includes all the functionalities of client
+ * side like binding the client side socket and connecting to the server
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+int8_t startL1AsClient(struct sockaddr_in serverPhy, struct sockaddr_in destinationPhy)
+{
+ if (bind(socket_fd, (struct sockaddr *)&serverPhy, sizeof(struct sockaddr_in ))<0)
+ {
+ DU_LOG("\nERROR --> PHY_STUB : bind failed");
+ return RFAILED;
+ }
+
+ while(true)
+ {
+ if (connect(socket_fd, (struct sockaddr *)&destinationPhy, sizeof(struct sockaddr_in)) < 0)
+ {
+ DU_LOG("\nERROR --> PHY_STUB : Connection Failed");
+ }
+ else
+ {
+ DU_LOG("\nINFO --> PHY_STUB : Client connected to sever");
+ break;
+ }
+ }
+ return ROK;
+
+}
+
+/*******************************************************************
+ *
+ * @brief this function creates the socket for commincation between source and
+ * target phy
+ *
+ * @details
+ *
+ * Function : establishConnectionWithPeerL1
+ *
+ * Functionality: creates the socket for commincation between source and
+ * target PHY, allocated the ip addresses and sends the request for connection
+ * establisshement and sends the information to each other
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+void *establishConnectionWithPeerL1(void *args)
+{
+ void *ret = NULLP;
+ struct sockaddr_in sourcePhy, destinationPhy;
+
+ if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
+ {
+ DU_LOG("\nERROR --> PHY_STUB : socket failed");
+ return ret;
+ }
+
+ sourcePhy.sin_family = AF_INET;
+ sourcePhy.sin_port = htons(phyDb.ipCfgInfo.portNumber);
+ sourcePhy.sin_addr.s_addr = phyDb.ipCfgInfo.sourceDu;
+
+ destinationPhy.sin_family = AF_INET;
+ destinationPhy.sin_port = htons(phyDb.ipCfgInfo.portNumber);
+ destinationPhy.sin_addr.s_addr = phyDb.ipCfgInfo.destinationDu;
+
+ if(phyDb.isServer)
+ {
+ if(startL1AsServer(sourcePhy, destinationPhy) != ROK)
+ {
+ DU_LOG("\nERROR --> PHY_STUB : Failed to start server");
+ return ret;
+ }
+ }
+ else
+ {
+ if(startL1AsClient(sourcePhy, destinationPhy) != ROK)
+ {
+ DU_LOG("\nERROR --> PHY_STUB : Failed to start client");
+ return ret;
+ }
+ }
+
+ DU_LOG("\nINFO --> PHY_STUB : Connection established");
+ receiveMsgFromPeerL1();
+ return ROK;
+}