A network optimization method, applied to a first network device and comprising: obtaining a metric for each of a plurality of data flows based on an internal gateway protocol, IGP, metric of a communications link between the first network device and a second network device; if it is detected that the communications link is in an abnormal state, adjusting the metric of at least one data flow among the plurality of data flows received by the first network device, wherein the metric is used to select a transmission path for the data flow corresponding to the metric; selecting the transmission path for the at least one data flow based on the adjusted metric; and transmitting the at least one data flow to the selected transmission path, wherein the obtaining a metric for each of a plurality of data flows specifically comprises: obtaining data information of the plurality of data flows, wherein the data information comprises at least service level agreement, SLA, information and priority information; dividing the IGP metric into a plurality of metric subsets based on SLA types indicated by the SLA information of the plurality of data flows, wherein each metric subset corresponds to one SLA type; dividing each metric subset into a plurality of sub-metrics based on priority information of a data flow corresponding to each SLA type, wherein each sub-metric is a metric of the corresponding data flow; and recording the plurality of sub-metrics and attribute information of the plurality of sub-metrics, wherein the attribute information is used to indicate an SLA type and priority information of the data flow corresponding to each of the plurality of sub-metrics. obtaining a metric for each of a plurality of data flows based on an internal gateway protocol, IGP, metric of a communications link between the first network device and a second network device; if it is detected that the communications link is in an abnormal state, adjusting the metric of at least one data flow among the plurality of data flows received by the first network device, wherein the metric is used to select a transmission path for the data flow corresponding to the metric; selecting the transmission path for the at least one data flow based on the adjusted metric; and transmitting the at least one data flow to the selected transmission path, wherein the obtaining a metric for each of a plurality of data flows specifically comprises: obtaining data information of the plurality of data flows, wherein the data information comprises at least service level agreement, SLA, information and priority information; dividing the IGP metric into a plurality of metric subsets based on SLA types indicated by the SLA information of the plurality of data flows, wherein each metric subset corresponds to one SLA type; dividing each metric subset into a plurality of sub-metrics based on priority information of a data flow corresponding to each SLA type, wherein each sub-metric is a metric of the corresponding data flow; and recording the plurality of sub-metrics and attribute information of the plurality of sub-metrics, wherein the attribute information is used to indicate an SLA type and priority information of the data flow corresponding to each of the plurality of sub-metrics. obtaining data information of the plurality of data flows, wherein the data information comprises at least service level agreement, SLA, information and priority information; dividing the IGP metric into a plurality of metric subsets based on SLA types indicated by the SLA information of the plurality of data flows, wherein each metric subset corresponds to one SLA type; dividing each metric subset into a plurality of sub-metrics based on priority information of a data flow corresponding to each SLA type, wherein each sub-metric is a metric of the corresponding data flow; and recording the plurality of sub-metrics and attribute information of the plurality of sub-metrics, wherein the attribute information is used to indicate an SLA type and priority information of the data flow corresponding to each of the plurality of sub-metrics.