From 03062e4c5b1356f5ff7fb8a109b8d6e74bc48c3e Mon Sep 17 00:00:00 2001 From: Valentina Schiavi Date: Thu, 19 Oct 2023 16:04:13 +0200 Subject: [PATCH 1/4] =?UTF-8?q?Modified=20services=20/v1/provide-mac-table?= =?UTF-8?q?-of-all-devices,=20/v1/provide-mac-table-of-specific-device=20a?= =?UTF-8?q?nd=20=E2=80=8B/v1=E2=80=8B/provide-list-of-network-element-inte?= =?UTF-8?q?rfaces-on-path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/service/IndividualServicesService.js | 177 +++++--------------- 1 file changed, 39 insertions(+), 138 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index a2b728c..60abbd5 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -179,6 +179,17 @@ exports.bequeathYourDataAndDie = function (body, user, originator, xCorrelator, }); } +function transformData(inputData) { + const outputData = { + "target-mac-address": `target-mac-address-${inputData["remote-mac-address"]}`, + "mount-name": inputData["mount-name"], + "original-ltp-name": inputData["original-ltp-name"], + "vlan-id": inputData["vlan-id"], + "time-stamp-of-data": new Date(inputData["time-stamp-of-data"]).toISOString() + }; + + return outputData; +} /** * Provides unsorted list of network element interfaces on path to specific MAC address. @@ -194,15 +205,16 @@ exports.bequeathYourDataAndDie = function (body, user, originator, xCorrelator, exports.provideListOfNetworkElementInterfacesOnPath = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { return new Promise(async function (resolve, reject) { let client = await elasticsearchService.getClient(false); + let targetMacAddress = body['target-mac-address']; let res2 = await client.search({ index: '6', - _source: 'targetMacAddress', + _source: 'mac-address', body: { query: { - regexp: { - 'targetMacAddress.target-mac-address.keyword': 'target-mac-address-'+ targetMacAddress + match: { + 'mac-address.remote-mac-address.keyword': targetMacAddress } } } @@ -212,13 +224,18 @@ exports.provideListOfNetworkElementInterfacesOnPath = async function (body, user const hits = res2.body.hits.hits; for (const hit of hits) { - const source = hit._source['targetMacAddress']; + const source = hit._source['mac-address']; mergedArray = mergedArray.concat(source); } + const filteredObjects = mergedArray.filter(obj => obj['remote-mac-address'] === targetMacAddress); + + const transformedArray = filteredObjects.map(obj => transformData(obj)); + + var response = {}; response['application/json'] = { - 'targetMacAddress': mergedArray + 'targetMacAddress': transformedArray }; if (Object.keys(response).length > 0) { @@ -305,14 +322,13 @@ exports.provideMacTableOfAllDevices = async function (user, originator, xCorrela let client = await elasticsearchService.getClient(false); - //let indexAlias = await getIndexAliasAsync(); let res2 = await client.search({ index: '6', // Sostituisci con il nome del tuo indice _source: 'mac-address', body: { query: { - regexp: { - 'mac-address.mount-name.keyword': 'mac-address-.*' + match: { + 'datatype': 'mac-address' } } } @@ -356,143 +372,28 @@ exports.provideMacTableOfAllDevices = async function (user, originator, xCorrela exports.provideMacTableOfSpecificDevice = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { return new Promise(async function (resolve, reject) { - /* - // TO FIX - //const PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice = - // await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice'); - - // OK -Elastic Search - let PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch = - await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName2('PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch'); - let operationNameAndOperationKey = - await resolveOperationNameAndOperationKeyFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch'); - let apiKey = operationNameAndOperationKey.operationName[onfAttributes.ES_CLIENT.API_KEY]; - let index = operationNameAndOperationKey.operationKey; - - let finalUrl = - //exports.dispatchEvent = function (url, method, httpRequestBody, Authorization) - result = await RestClient.dispatchEvent(finalUrl, 'GET', '', apiKey); - - // OK - Mwdi - matr-1-0-0-http-c-mwdi-1-0-0-000 - let applicationNameAndHttpClient = - await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName2('PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi'); - operationNameAndOperationKey = - await resolveOperationNameAndOperationKeyFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi'); - - let applicationName = applicationNameAndHttpClient.applicationName; - let operationName = operationNameAndOperationKey.operationName; - let authorizationCode = operationNameAndOperationKey.operationKey; - - let logicalTerminationPointListTCP = await controlConstruct.getLogicalTerminationPointListAsync(LayerProtocol.layerProtocolNameEnum.TCP_CLIENT); - let ltpTcpUuid; - for (const ltp of logicalTerminationPointListTCP) { - const clientLtp = ltp[onfAttributes.LOGICAL_TERMINATION_POINT.CLIENT_LTP]; - if (applicationNameAndHttpClient.httpClientLtpUuid === clientLtp[0]) { - ltpTcpUuid = ltp[onfAttributes.GLOBAL_CLASS.UUID]; - } - } - - let remoteTcpAddress = await tcpClientInterface.getRemoteAddressAsync(ltpTcpUuid); - let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); - - finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - //const result = await RestClient.dispatchEvent(finalUrl, 'GET', '', authorizationCode); - - //OK - Mwdi - const PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi = - await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName2('PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi'); - - operationNameAndOperationKey = - await resolveOperationNameAndOperationKeyFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi'); - - applicationName = applicationNameAndHttpClient.applicationName; - operationName = operationNameAndOperationKey.operationName; - - logicalTerminationPointListTCP = await controlConstruct.getLogicalTerminationPointListAsync(LayerProtocol.layerProtocolNameEnum.TCP_CLIENT); - ltpTcpUuid; - for (const ltp of logicalTerminationPointListTCP) { - const clientLtp = ltp[onfAttributes.LOGICAL_TERMINATION_POINT.CLIENT_LTP]; - if (applicationNameAndHttpClient.httpClientLtpUuid === clientLtp[0]) { - ltpTcpUuid = ltp[onfAttributes.GLOBAL_CLASS.UUID]; - } - } - - remoteTcpAddress = await tcpClientInterface.getRemoteAddressAsync(ltpTcpUuid); - remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); - - finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - result = await RestClient.dispatchEvent(finalUrl, 'GET', '', authorizationCode); - - - - // TO FIX - /*const PromptForUpdatingMacTableFromDeviceCausesSendingAnswerToRequestor = - await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName2('PromptForUpdatingMacTableFromDeviceCausesSendingAnswerToRequestor'); + let client = await elasticsearchService.getClient(false); + let mountName = body['mount-name']; - let applicationName = applicationNameAndHttpClient.applicationName;*/ - /*let operationName = "/rests/operations/network-topology:network-topology/topology=topology-netconf/node={mount-name}/yang-ext:mount/mac-fd-1-0:provide-learned-mac-addresses"; + let res2 = await client.get({ + index: '6', + id: mountName + }); - let applicationName = "OpenDayLight"; - let authorizationCode = "Basic c2lhZTpTaUdlbjAx"; - let userName = exports.decodeAuthorizationCodeAndExtractUserName(authorizationCode); - let applicationReleaseNumber = await httpServerInterface.getReleaseNumberAsync();*/ - /*let httpRequestHeader = onfAttributeFormatter.modifyJsonObjectKeysToKebabCase(new RequestHeader(userName, applicationName, "", "", "unknown", operationKey)); + var source = res2.body._source['mac-address']; + var response = {}; + response['application/json'] = { + 'mac-address': source + }; - let request = { - method: GET, - url: url, - headers: httpRequestHeader, - data: "" + if (Object.keys(response).length > 0) { + resolve(response['application/json']['mac-address']); + } else { + resolve(); } - let response = await RestClient.post(request); - - let forwardingConstructInstance = await ForwardingDomain.getForwardingConstructForTheForwardingNameAsync(forwardingKindName); - let operationClientUuid = (getFcPortOutputLogicalTerminationPointList(forwardingConstructInstance))[0];*/ - - //let finalUrl = "http://172.28.127.3:8181/rests/data/network-topology:network-topology/topology=topology-netconf/node=513250009/yang-ext:mount/core-model-1-4:control-construct"; - //let finalUrl = "http://172.28.127.3:8181/rests/operations/network-topology:network-topology/topology=topology-netconf/node=513250009/yang-ext:mount/mac-fd-1-0:provide-learned-mac-addresses"; - - //const result = await RestClient.dispatchEvent(finalUrl, 'GET', '', authorizationCode); - - - let client = await elasticsearchService.getClient(false); - let mountName = body['mount-name']; - - let regValue ='mac-address-'+ mountName; - - let res2 = await client.search({ - index: '6', - _source: 'mac-address', - body: { - query: { - regexp: { - 'mac-address.mount-name.keyword': 'mac-address-'+ mountName - } - } - } - }); - - let mergedArray = []; - - const hits = res2.body.hits.hits; - for (const hit of hits) { - const source = hit._source['mac-address']; - mergedArray = mergedArray.concat(source); - } - - var response = {}; - response['application/json'] = { - 'mac-address': mergedArray - }; - - if (Object.keys(response).length > 0) { - resolve(response['application/json']['mac-address']); - } else { - resolve(); - } }); } From 09cc993a395b6ee4ff47a092e8550e153e081d35 Mon Sep 17 00:00:00 2001 From: Valentina Schiavi Date: Fri, 3 Nov 2023 13:56:21 +0100 Subject: [PATCH 2/4] refactor /v1/read-current-mac-table-from-device --- server/service/IndividualServicesService.js | 256 ++++++++++++++------ 1 file changed, 185 insertions(+), 71 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 8d52d53..0bfe668 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -306,7 +306,7 @@ exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentation = fun function orderData(input) { - + const output = { "mount-name": input['mount-name'], "own-mac-address": input['own-mac-address'], @@ -370,8 +370,8 @@ const PromptForProvidingAllMacTablesCausesReadingFromElasticSearch = async funct exports.provideMacTableOfAllDevices = async function (user, originator, xCorrelator, traceIndicator, customerJourney) { return new Promise(function (resolve, reject) { PromptForProvidingAllMacTablesCausesReadingFromElasticSearch() - .then(function (response) { - const orderedArray = response.map(obj => orderData(obj)); + .then(function (response) { + const orderedArray = response.map(obj => orderData(obj)); //console.log("Data from orderedArray:", response); resolve(orderedArray); }) @@ -465,7 +465,7 @@ function customEncode(input) { //STEP 1 -async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi(body, user, originator, xCorrelator, traceIndicator, customerJourney) { +async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi(mountName, user, originator, xCorrelator, traceIndicator, customerJourney) { try { let applicationNameAndHttpClient = await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi'); @@ -509,8 +509,6 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched let url = ""; let baseUrl = ""; - let mountName = body['mount-name']; - if (splitUrl.length > 1) { baseUrl = splitUrl[0]; fields = splitUrl[1]; @@ -537,7 +535,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearched } //STEP 2 -async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney) { +async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(mountName, user, originator, xCorrelator, traceIndicator, customerJourney) { try { let applicationNameAndHttpClient = await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice'); @@ -574,7 +572,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr operationKey ); - let mountName = body['mount-name']; + let fullUrl = finalUrl.replace("{mount-name}", mountName); @@ -615,10 +613,15 @@ async function PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFr } - //STEP 3 -async function PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(body, user, originator, xCorrelator, traceIndicator, customerJourney) { +async function PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(body, uuid, originator, xCorrelator, traceIndicator, customerJourney) { try { + + if (body['egress-ltp'] == "LTP-MNGT") { + body['original-ltp-name'] = "LAN-MNGT" + return body; + } + // matr-1-0-0-op-c-is-mwdi-1-0-0-001 let applicationNameAndHttpClient = await resolveApplicationNameAndHttpClientLtpUuidFromForwardingName('PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi'); @@ -645,8 +648,7 @@ async function PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIn let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + operationName; - let mountName = body['mount-name']; - let uuid = mountName + "+" + body['uuid']; + uuid = mountName + "+" + uuid; let finalUrlTmp = finalUrl.replace("{mount-name}", mountName); finalUrl = finalUrlTmp.replace("{uuid}", uuid); @@ -702,34 +704,12 @@ async function PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch let remoteTcpAddress = await tcpClientInterface.getRemoteAddressAsync(ltpTcpUuid); let remoteTcpPort = await tcpClientInterface.getRemotePortAsync(ltpTcpUuid); + let mountName = body["mac-address"][0]["mount-name"]; - let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + "/" + operationKey + "/_doc/305251234"; + let finalUrl = "http://" + remoteTcpAddress["ip-address"]["ipv-4-address"] + ":" + remoteTcpPort + "/" + operationKey + "/_doc/" + mountName; - var data = { - "datatype": "mac-address", - "mac-address": - [ - { - "mount-name": "305251234", - "own-mac-address": "00:00:00:00:00:00", - "egress-ltp-uuid": "305251234+mac-inf-VALE", - "original-ltp-name": "eth-1-0-3", - "vlan-id": 17, - "remote-mac-address": "01:01:01:01:01:01", - "time-stamp-of-data": "2010-11-20T13:00:00.000Z" - }, - { - "mount-name": "305251234", - "own-mac-address": "00:00:00:00:00:00", - "egress-ltp-uuid": "305251234+mac-inf-VALE", - "original-ltp-name": "eth-1-0-3", - "vlan-id": 17, - "remote-mac-address": "FF:01:01:01:01:01", - "time-stamp-of-data": "2010-11-20T13:00:00.000Z" - } - ] - }; + var data = body; let originator = await httpServerInterface.getApplicationNameAsync(); let httpRequestHeader = new RequestHeader( @@ -782,15 +762,20 @@ async function PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch * customerJourney String Holds information supporting customer’s journey to which the execution applies * returns inline_response_200_2 **/ +/* exports.readCurrentMacTableFromDevice = function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { let dataFromRequest; const uuidArray = []; + let egressArray = []; + let uuidEgress = 0; - return new Promise(async function (resolve, reject) { + return new Promise(async function (resolve, reject) { + let error = false; //STEP1 - MIDW call (MWDI://core-model-1-4:network-control-domain=cache/control-construct={mount-name}?\nfields=forwarding-domain(uuid;layer-protocol-name;mac-fd-1-0:mac-fd-pac(mac-fd-status(mac-address-cur)))) - /* - PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi(body, user, originator, xCorrelator, traceIndicator, customerJourney) + + let mountName = body['mount-name']; + PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi(mountName, user, originator, xCorrelator, traceIndicator, customerJourney) .then(data => { dataFromRequest = data; data["core-model-1-4:control-construct"].forEach(controlConstruct => { @@ -804,55 +789,184 @@ exports.readCurrentMacTableFromDevice = function (body, user, originator, xCorre } }); }); + + if (uuidArray.length != 0) { + //STEP2 - ODL call (POST ODL://...mac-fd-1-0:provide-learned-mac-addresses) + PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(mountName, user, originator, xCorrelator, traceIndicator, customerJourney) + .then(data => { + dataFromRequest = data; + + const egressSet = new Set(); // Utilizza un Set per memorizzare valori univoci + + dataFromRequest["mac-fd-1-0:output"]["mac-table-entry-list"].forEach(entry => { + if (entry["affected-mac-fd"] === "MAC-FD") { + egressSet.add(entry["egress-ltp"]); + } + }); + + egressArray = Array.from(egressSet); + + const promises = egressArray.map(uuid => { + //STEP3 + PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(mountName, uuid, originator, xCorrelator, traceIndicator, customerJourney) + .then(data => { + // Esegui operazioni sui dati + console.log('Dati:', data); + return data; // Restituisci il valore per la promessa + }) + .catch(error => { + // Gestisci l'errore per questa promessa, ma continua con le altre + console.error('Errore durante la richiesta:', error); + return null; // Restituisci un valore speciale o null, se necessario + }); + }); + + }) + .catch(error => { + console.error('Error during request:', error); + error = true; + }); + } }) .catch(error => { - console.error('Errore durante la richiesta:', error); - }); - */ + console.error('Error during request:', error); + error = true; + });*/ + + + +//STEP3 - MIDW call (MWDI://core-model-1-4:network-control-domain=cache/control-construct={mount-name}/logical-termination-point={uuid}/ltp-augment-1-0:ltp-augment-pac?\nfields=original-ltp-name) +/* +PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(body, user, originator, xCorrelator, traceIndicator, customerJourney) +.then(data => { + dataFromRequest = data; +}) +.catch(error => { + console.error('Errore durante la richiesta:', error); +}); +*/ + + +//STEP4 - PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch +//"ElasticSearch": {MountName, macAddressCur, egressLtpUUid, originalLtpName, vlanId, macAddresses, timeStampOfRpc} +/* +PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch(body, user, originator, xCorrelator, traceIndicator, customerJourney) + .then(data => { + dataFromRequest = data; + }) + .catch(error => { + console.error('Errore durante la richiesta:', error); + }); +*/ +// }); +//} - //STEP2 - ODL call (POST ODL://...mac-fd-1-0:provide-learned-mac-addresses) - PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(body, user, originator, xCorrelator, traceIndicator, customerJourney) - .then(data => { - dataFromRequest = data; - }) - .catch(error => { - console.error('Errore durante la richiesta:', error); - }); +function createMacAddressEntry(mountName, ownMacAddress, egressLtpUuid, originalLtpName, vlanId, remoteMacAddress, timeStamp) { + return { + "mount-name": mountName, + "own-mac-address": ownMacAddress, + "egress-ltp-uuid": egressLtpUuid, + "original-ltp-name": originalLtpName, + "vlan-id": vlanId, + "remote-mac-address": remoteMacAddress, + "time-stamp-of-data": timeStamp + }; +} + +function createMacAddressData(datatype, macAddressArray) { + return { + "datatype": datatype, + "mac-address": macAddressArray + }; +} + + +exports.readCurrentMacTableFromDevice = async function (body, user, originator, xCorrelator, traceIndicator, customerJourney) { + + const FDomainArray = []; + let step2DataArray = []; + let originalLtpNameArray = 0; + let uuidEgress = 0; + let step2Data = []; + let macAddressArray = []; + try { - //STEP3 - MIDW call (MWDI://core-model-1-4:network-control-domain=cache/control-construct={mount-name}/logical-termination-point={uuid}/ltp-augment-1-0:ltp-augment-pac?\nfields=original-ltp-name) - /* - PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(body, user, originator, xCorrelator, traceIndicator, customerJourney) - .then(data => { - dataFromRequest = data; - }) - .catch(error => { - console.error('Errore durante la richiesta:', error); + //STEP1 + const mountName = body['mount-name']; + const data = await PromptForUpdatingMacTableFromDeviceCausesUuidOfMacFdBeingSearchedAndManagementMacAddressBeingReadFromMwdi(mountName, user, originator, xCorrelator, traceIndicator, customerJourney); + + data["core-model-1-4:control-construct"].forEach(controlConstruct => { + controlConstruct["forwarding-domain"].forEach(forwardingDomain => { + if ( + forwardingDomain["layer-protocol-name"].includes( + "mac-interface-1-0:LAYER_PROTOCOL_NAME_TYPE_MAC_LAYER" + ) + ) { + FDomainArray.push(forwardingDomain); + } + }); }); - */ - //STEP4 - PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch - //"ElasticSearch": {MountName, macAddressCur, egressLtpUUid, originalLtpName, vlanId, macAddresses, timeStampOfRpc} - /* - PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch(body, user, originator, xCorrelator, traceIndicator, customerJourney) - .then(data => { - dataFromRequest = data; - }) - .catch(error => { - console.error('Errore durante la richiesta:', error); + if (FDomainArray.length > 0) { + const dataFromRequest = await PromptForUpdatingMacTableFromDeviceCausesMacTableBeingRetrievedFromDevice(mountName, user, originator, xCorrelator, traceIndicator, customerJourney); + + let uuid = FDomainArray[0]['uuid'].split("+")[1]; + let macAddressCur = FDomainArray[0]['mac-fd-1-0:mac-fd-pac']['mac-fd-status']['mac-address-cur']; + + const egressSet = new Set(); + dataFromRequest["mac-fd-1-0:output"]["mac-table-entry-list"].forEach(entry => { + if (entry["affected-mac-fd"] === uuid) { + entry["own-mac-address"] = macAddressCur; + egressSet.add(entry); + } }); - */ + const step2DataArray = Array.from(egressSet); + const originalLtpNamePromises = step2DataArray.map(egressData => { + return PromptForUpdatingMacTableFromDeviceCausesLtpUuidBeingTranslatedIntoLtpNameBasedOnMwdi(egressData, user, originator, xCorrelator, traceIndicator, customerJourney); + }); + const step3DataArray = await Promise.all(originalLtpNamePromises); + + // Esegui un loop su originalLtpNames + step3DataArray.forEach((step3Data, index) => { + // Puoi accedere a ciascun originalLtpName all'interno del loop + console.log('OriginalLtpName ${index}:' + step3Data['own-mac-address']); + const entry = createMacAddressEntry( + mountName, + step3Data['own-mac-address'], + step3Data['egress-ltp'], + step3Data['original-ltp-name'], + step3Data['vlan-id'], + step3Data['mac-address'], + "2010-11-20T14:00:00+01:00"); + macAddressArray.push(entry); + }); - }); + const macAddressData = createMacAddressData("mac-address", macAddressArray); + + const writingResultPromise = await PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch(macAddressData, user, originator, xCorrelator, traceIndicator, customerJourney); + var examples = {}; + examples['application/json'] = { + "request-id" : "305251234-101120-1414" + }; + return(examples['application/json']); + } + } + catch (error) { + console.error('Errore durante la richiesta:', error); + throw error; + } } + + From 3871d95f09e0923e289c27a0c023ace129437ee5 Mon Sep 17 00:00:00 2001 From: Valentina Schiavi Date: Fri, 3 Nov 2023 16:46:32 +0100 Subject: [PATCH 3/4] Fix validation problem on vlanId (must be an integer) --- server/service/IndividualServicesService.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 0bfe668..84d2981 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -869,7 +869,7 @@ function createMacAddressEntry(mountName, ownMacAddress, egressLtpUuid, original "own-mac-address": ownMacAddress, "egress-ltp-uuid": egressLtpUuid, "original-ltp-name": originalLtpName, - "vlan-id": vlanId, + "vlan-id": parseInt(vlanId), "remote-mac-address": remoteMacAddress, "time-stamp-of-data": timeStamp }; @@ -887,9 +887,6 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, const FDomainArray = []; let step2DataArray = []; - let originalLtpNameArray = 0; - let uuidEgress = 0; - let step2Data = []; let macAddressArray = []; try { From 858fe41bcf57abc01dc8b93a9c3f33abe8776d1a Mon Sep 17 00:00:00 2001 From: Valentina Schiavi Date: Mon, 13 Nov 2023 10:29:51 +0100 Subject: [PATCH 4/4] Implement service /v1/read-current-mac-table-from-device Fixes #103 --- server/controllers/BasicServices.js | 9 +++++---- server/controllers/IndividualServices.js | 14 +++++++------- server/service/IndividualServicesService.js | 5 +++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server/controllers/BasicServices.js b/server/controllers/BasicServices.js index 308e558..6d0bbac 100644 --- a/server/controllers/BasicServices.js +++ b/server/controllers/BasicServices.js @@ -2,13 +2,14 @@ var utils = require('../utils/writer.js'); var BasicServices = require('onf-core-model-ap-bs/basicServices/BasicServicesService'); -var responseBuilder = require('onf-core-model-ap/applicationPattern/rest/server/ResponseBuilder'); +var RestResponseBuilder = require('onf-core-model-ap/applicationPattern/rest/server/ResponseBuilder'); var responseCodeEnum = require('onf-core-model-ap/applicationPattern/rest/server/ResponseCode'); -var restResponseHeader = require('onf-core-model-ap/applicationPattern/rest/server/ResponseHeader'); +var RestResponseHeader = require('onf-core-model-ap/applicationPattern/rest/server/ResponseHeader'); +var ExecutionAndTraceService = require('onf-core-model-ap/applicationPattern/services/ExecutionAndTraceService'); module.exports.embedYourself = async function embedYourself(req, res, next, body, user, originator, xCorrelator, traceIndicator, customerJourney) { let startTime = process.hrtime(); - let responseCode = responseCodeEnum.code.NO_CONTENT; + let responseCode = responseCodeEnum.code.OK; let responseBodyToDocument = {}; await BasicServices.embedYourself(body, user, xCorrelator, traceIndicator, customerJourney, req.url) @@ -223,7 +224,7 @@ module.exports.registerYourself = async function registerYourself(req, res, nex let startTime = process.hrtime(); let responseCode = responseCodeEnum.code.NO_CONTENT; let responseBodyToDocument = {}; - if (Object.keys(req.body).length === 0) { + if (Object.keys(req.body).length === 0) { body = req.body; user = req.headers["user"]; originator = req.headers["originator"]; diff --git a/server/controllers/IndividualServices.js b/server/controllers/IndividualServices.js index bbc539d..fc042e4 100644 --- a/server/controllers/IndividualServices.js +++ b/server/controllers/IndividualServices.js @@ -4,8 +4,8 @@ var utils = require('../utils/writer.js'); var IndividualServices = require('../service/IndividualServicesService'); var executionAndTraceService = require('onf-core-model-ap/applicationPattern/services/ExecutionAndTraceService'); var responseCodeEnum = require('onf-core-model-ap/applicationPattern/rest/server/ResponseCode'); -var restResponseHeader = require('onf-core-model-ap/applicationPattern/rest/server/ResponseHeader'); -var restResponseBuilder = require('onf-core-model-ap/applicationPattern/rest/server/ResponseBuilder'); +var ResponseHeader = require('onf-core-model-ap/applicationPattern/rest/server/ResponseHeader'); +var ResponseBuilder = require('onf-core-model-ap/applicationPattern/rest/server/ResponseBuilder'); const RequestBuilder = require('onf-core-model-ap/applicationPattern/rest/client/RequestBuilder'); @@ -44,7 +44,7 @@ module.exports.provideListOfNetworkElementInterfacesOnPath = async function prov responseCode = sentResp.code; responseBodyToDocument = sentResp.body; }); - //executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); + executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); }; @@ -64,7 +64,7 @@ module.exports.provideListOfNetworkElementInterfacesOnPathInGenericRepresentatio responseCode = sentResp.code; responseBodyToDocument = sentResp.body; }); - //executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); + executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); }; module.exports.provideMacTableOfAllDevices = async function provideMacTableOfAllDevices (req, res, next, user, originator, xCorrelator, traceIndicator, customerJourney) { @@ -83,7 +83,7 @@ module.exports.provideMacTableOfAllDevices = async function provideMacTableOfAll responseCode = sentResp.code; responseBodyToDocument = sentResp.body; }); - //executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); + executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); }; module.exports.provideMacTableOfSpecificDevice = async function provideMacTableOfSpecificDevice (req, res, next, body, user, originator, xCorrelator, traceIndicator, customerJourney) { @@ -102,7 +102,7 @@ module.exports.provideMacTableOfSpecificDevice = async function provideMacTableO responseCode = sentResp.code; responseBodyToDocument = sentResp.body; }); - //executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); + executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); }; module.exports.readCurrentMacTableFromDevice = async function readCurrentMacTableFromDevice (req, res, next, body, user, originator, xCorrelator, traceIndicator, customerJourney) { @@ -121,5 +121,5 @@ module.exports.readCurrentMacTableFromDevice = async function readCurrentMacTabl responseCode = sentResp.code; responseBodyToDocument = sentResp.body; }); - //executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); + executionAndTraceService.recordServiceRequest(xCorrelator, traceIndicator, user, originator, req.url, responseCode, req.body, responseBodyToDocument); }; diff --git a/server/service/IndividualServicesService.js b/server/service/IndividualServicesService.js index 4080d04..8d469ef 100644 --- a/server/service/IndividualServicesService.js +++ b/server/service/IndividualServicesService.js @@ -968,12 +968,13 @@ exports.readCurrentMacTableFromDevice = async function (body, user, originator, const writingResultPromise = await PromptForUpdatingMacTableFromDeviceCausesWritingIntoElasticSearch(macAddressData, user, originator, xCorrelator, traceIndicator, customerJourney); + //TO FIX: var examples = {}; examples['application/json'] = { - "request-id" : "305251234-101120-1414" + "request-id": "305251234-101120-1414" }; - return(examples['application/json']); + return (examples['application/json']); } }