Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tfs/controller
1 result
Show changes
Showing
with 2800 additions and 0 deletions
<!-- Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<config>
<!-- TCP port where the BGP is listening for incoming bgp4 connections. Optional Parameter. Default value: 179 (BGP Port) -->
<BGP4Port>12179</BGP4Port>
<BGPIdentifier>7.7.7.7</BGPIdentifier>
<!-- TCP port to connect to manage the BGP connection. Default value: 1112 -->
<BGP4ManagementPort>1112</BGP4ManagementPort>
<!-- Peers to which this Peer is going to establish connection -->
<configPeer>
<peer>10.95.90.43</peer>
<export>false</export>
<import>true</import>
<peerPort>179</peerPort>
</configPeer>
<!-- Ficheros log (servidor, protocolo PCEP y OSPF). Campos opcionales-->
<BGP4LogFile>BGP4Parser2.log</BGP4LogFile><!-- Default value: BGP4Parser.log -->
<BGP4LogFileClient>BGP4Client2.log</BGP4LogFileClient><!-- Default value: BGP4Client.log-->
<BGP4LogFileServer>BGP4Server2.log</BGP4LogFileServer><!-- Default value: BGP4Server.log-->
<!-- If the tcp no delay option is used or not. Optional Parameter. Default value: false. -->
<nodelay>true</nodelay>
<!-- Waiting Time to re-connect to clients. Default value: 6000 ms. -->
<delay>40000</delay>
<setTraces>true</setTraces>
<!-- OPEN Parameters -->
<!-- RFC 4271. This 2-octet unsigned integer indicates the number of seconds the sender proposes for the value of the Hold Timer.
Upon receipt of an OPEN message, a BGP speaker MUST calculate the value of the Hold Timer by using the smaller of its configured
Hold Time and the Hold Time received in the OPEN message. The Hold Time MUST be either zero or at least three seconds. An
implementation MAY reject connections on the basis of the Hold Time. The calculated value indicates the maximum number of
seconds that may elapse between the receipt of successive KEEPALIVE and/or UPDATE messages from the sender. -->
<holdTime>180</holdTime><!-- Optional Parameter. Default value: 3. -->
<!-- RFC 4271. This 1-octet unsigned integer indicates the protocol version number of the message. The current BGP version number is 4. -->
<version>4</version><!-- Optional Parameter. Default value: 4. -->
<!-- RFC 4271. This 2-octet unsigned integer indicates the Autonomous System number of the sender.-->
<myAutonomousSystem>100</myAutonomousSystem>
<!-- RFC 4271. This 4-octet unsigned integer indicates the BGP Identifier of the sender. A given BGP speaker sets the value of its BGP
Identifier to an IP address that is assigned to that BGP speaker. The value of the BGP Identifier is determined upon
startup and is the same for every local interface and BGP peer. -->
<!--<BGPIdentifier>192.168.1.200</BGPIdentifier> -->
<!-- If the peer is in charge of sending its topology (only the interdomain Links) to the other BGP peer it is connected to. Default: false -->
<sendTopology>false</sendTopology>
<!-- If the peer is in charge of sending its whole topology to the other BGP peer it is connected to. Default: false -->
<sendIntradomainLinks>true</sendIntradomainLinks>
<!-- Optional Parameter. How to learn the topology. Possibilities: fromXML, fromBGP. Default: fromBGP -->
<learnTopology>fromBGP</learnTopology>
<!-- Topology network to read. It is mandatory if and only if learnTopology parameter is fromXML. -->
<!--<topologyFile>src/test/resources/network1.xml</topologyFile>-->
<!-- Optional Parameter. Instance Identifier for node and link NLRI. See rfc 6549. Default value: 0-->
<!--<instanceID>0</instanceID>-->
<!-- Optional Parameter. Default value: localhost -->
<localBGPAddress>0.0.0.0</localBGPAddress>
</config>
\ No newline at end of file
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
v1.3.3
- Topology Module added
- Topology Module: Export via RESCONF with COP model
- Topology Module: Export via RESTCONF with IETF model (nodes only)
- Topology Module: Export via UNIFY model
- Topology Module: Import via XML
- Topology Module: Import/Export via BGP-LS
v1.3.2
- Supports network-protocols 1.3.2
- Update to support reading multiple AS_PATH
- Apache 2.0 license
- Moved to slf4j logging framework
- Added method to pass multiple TEDs from en external program
- Added docker support in travis
v1.3
- Compile with networking-protocols v1.3.0 (available in maven central)
- JUnit Test upgrade to check intraTEDBs after sending
- Added functionality: read multiple intraTEDBs from xml file
- Added support to draft-previdi-idr-bgpls-te-metric-extensions-00
v1.2.2
- Added travis integration
- Javadoc errors fixed
- Ready to meet maven central requirements
- Compile with networking-protocols v1.2.3 (available in maven central)
v1.2.1
- Compile with networking-protocols v1.2.1
v1.2
- JUnit Test added
- Bugfixes
- Reduced number of logs
- Updated README with explanation of parameters
v1.1.1
- Added configuration instructions of the standalone BGP Peer
- Added dependencies to pom.xml
v1.1.0
First Public Release
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
1.3.3
<!-- Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
#Examples
##Topology Module Examples
Two sets of basic configuration files are here included with Topology Module software: the setup for running three TM within the same machine (configuration A) and the setup for running three TM in three dedicated machines (configuration B). In both cases three example network topologies are provided to represent the abstract topology of 2 end-point providers and 1 transit provider.
### Example TM1: 1 Way Test in the same virtual machine, BPG-LS Plugin and UNIFY Export.
The setup has been provided just for testing purpose and configures 3 TADS in the same machine to perform unidirectional information exchange.
![1WayTest](figures/1wayTest.png?raw=true "Test with 3 TM")
The reference files, including Topology Module configuration, BGP-LS Plugin configuration and abstracted topologies are copiend in the folder target/conf1wayTest after the maven installation. Be sure to compile also the Topology Module as indicated in README.md.
To execute TM1 run:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/topology-1.3.3-shaded.jar target/conf1wayTest/TM1.xml
```
To execute TM2 run:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/topology-1.3.3-shaded.jar target/conf1wayTest/TM2.xml
```
To execute TM3 run:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/topology-1.3.3-shaded.jar target/conf1wayTest/TM3.xml
```
To verify the retrieved information:
```bash
curl http://localhost:8087/restconf/data/virtualizer/ | python -m json.tool
```
[for TADS2]
```bash
curl http://localhost:8088/restconf/data/virtualizer/ | python -m json.tool
```
[for TADS3]
```bash
curl http://localhost:8089/restconf/data/virtualizer/ | python -m json.tool
```
### Example TM2: 2 Way Test in the different virtual machines, BPG-LS Plugin and UNIFY Export.
The setup has been provided as reference configuration for the configuration of 3 TM in dedicated machines to perform bidirectional exchange of information
![1WayTest](figures/2wayTest.png?raw=true "Test with 3 TM in 3 different machines")
The reference files, including Topology Module configuration, BGP-LS Plugin configuration and abstracted topologies are in
```bash
target/conf2waysReal
```
Before running the reference scenario be sure to complete the IP configuration in the 3 modules, in fact, according to previous description, minor ad-hoc changes are needed.
In the Topology Module configuration files (TM*.xml):
• set the IP address used for the BGP-LS communication as Identifier
In the BGP-LS Plugin configuration (BGPLS*_2way.xml):
• set the IP address used for the BGP-LS communication as BGPIdentifier
• configure the peers as needed (IP address and port)
[where * = 1,2,3]
To execute TADS1 in machine 1 run:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/topology-1.3.3-shaded.jar target/conf1wayTest/TM1.xml
```
To execute TADS1 in machine 2 run:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/topology-1.3.3-shaded.jar target/conf1wayTest/TM2.xml
```
To execute TADS1 in machine 3 run:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/topology-1.3.3-shaded.jar target/conf1wayTest/TM3.xml
```
To verify the retrieved information:
[for TADS2, in machine 1]
```bash
curl http://localhost:8088/restconf/data/virtualizer/ | python -m json.tool
```
[for TADS2, in machine 2]
```bash
>curl http://localhost:8088/restconf/data/virtualizer/ | python -m json.tool
```
[for TADS3, in machine 3]
```bash
>curl http://localhost:8088/restconf/data/virtualizer/ | python -m json.tool
```
### Topology module with BGP-LS and COP plugins and BGP-LS speaker
In this example there are 2 BGP-LS speakers, one acting as sender of topology, and the other as consumer. A small topology is loaded from an xml file in BGP-LS Speaker #1. This topology is sent to BGP-LS Speaker #2.
```bash
TBD
```
### Topology module with BGP-LS and COP plugins and Topology module with BGP-LS speaker
In this example there are 2 BGP-LS speakers, one acting as sender of topology, and the other as consumer. A small topology is loaded from an xml file in BGP-LS Speaker #1. This topology is sent to BGP-LS Speaker #2.
```bash
TBD
```
## BGP-LS Speaker Examples
### BPP-LS Speaker Example 1
In this example there are 2 BGP-LS speakers, one acting as sender of topology, and the other as consumer. A small topology is loaded from an xml file in BGP-LS Speaker #1. This topology is sent to BGP-LS Speaker #2.
To launch BGP-LS Speaker #1:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/bgp-ls-speaker-jar-with-dependencies.jar target/bgpls_example1/BGP4Parameters_1.xml
```
BGP-LS Speaker #2:
```bash
sudo java -Dlog4j.configurationFile=target/log4j2.xml -jar target/bgp-ls-speaker-jar-with-dependencies.jar target/bgpls_example1/BGP4Parameters_2.xml
```
To verify the retrieved information:
```bash
telnet localhost 1112
show topology
```
Then, the topology is printed on screen.
<!-- Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
# Example 1: TM with XML Plugin and TAPI Plugin
- First of all, compile the full-jar if you have not done so
```bash
mvn package -P generate-full-jar
```
Execute the server
```bash
sudo java -Dlog4j.configurationFile=target/examples/log4j2.xml -jar target/topology-1.3.4-SNAPSHOT-shaded.jar target/TM_TAPI_example1/TMConfTAPI.xml
```
Make the query
```bash
curl http://localhost:8089/config/context/topology -X GET -i -H "Content-Type: application/json" -H "Accept: application/json"
```
<!-- Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
# Topology XML File
This section describes the topology file format, used by the TADS to load the abstracted view of the local provider.
The reference file for this description is
```
target/conf1wayTest/network1.xml
```
The main tag of the file is **network** that can include multiple **domains**, each domain represents a provider.
```xml
<network>
<domain>
</domain>
<domain>
</domain>
</network>
```
In this case the network topology includes two providers.
The first part of the each domain contains some general information:
- **domain_id**: the AS number of the domain represented in IPv4 format
- the **reachability_entry**: that summarizes the prefix network for the provider (IPv4 network prefix and mask)
- **it_resources**: here the information related to overall IT resources availability is described considering
- **controller_it**: the entry point for 5GEx orchestration
- **cpu**: overall available CPUs
- **mem**: overall available memory
- **storage**: overall available storage
```xml
<domain_id>0.0.0.1</domain_id>
<reachability_entry>
<ipv4_address>172.16.101.0</ipv4_address>
<prefix>24</prefix>
</reachability_entry>
<it_resources>
<controller_it>https://openstack.5Gex.com/url</controller_it>
<cpu>100</cpu>
<mem>100Gbyte</mem>
<storage>100Tbyte</storage>
</it_resources>
```
Then the file is organized considering a list of nodes and a list unidirectional links.
Each node is represented with a tag **node** and is identified with an IPv4 id called **router_id**
```xml
<node>
<router_id>172.16.101.101</router_id>
</node>
<node>
<router_id>172.16.101.102</router_id>
</node>
<node>
<router_id>172.16.101.103</router_id>
</node>
<node>
<router_id>172.16.101.104</router_id>
</node>
```
In the reference case 4 nodes are considered.
Each link is identified by the tag **edge**.
The link description include:
- **source**: the source node of the link, identified with the pair **router_id** and interface id, **if_id**
- **destination**: the destination node of the link, identified with the pair router_id and interface
- **TE parameters**: several possibilities are available, in the considered example the focus was on
- unidirectional link delay
- minimum experienced delay
- maximum experienced delay
```xml
<edge>
<source>
<router_id>172.16.101.101</router_id>
<if_id>1</if_id>
</source>
<destination>
<router_id>172.16.101.104</router_id>
<if_id>1</if_id>
</destination>
<undir_delay_link>99</undir_delay_link>
<undir_min_max_delay>
<min>23</min>
<max>250</max>
</undir_min_max_delay>
</edge>
```
For setting up default TE parameters for all the network links, the **edgeCommon** tag is used.
```xml
<edgeCommon>
<undir_delay_link>99</undir_delay_link>
<undir_min_max_delay>
<min>23</min>
<max>43</max>
</undir_min_max_delay>
<undir_delay_variation>1</undir_delay_variation>
<undir_link_loss>102</undir_link_loss>
<undir_residual_bandwidth>802</undir_residual_bandwidth>
<undir_available_bandwidth>500</undir_available_bandwidth>
<undir_utilized_bandwidth>436</undir_utilized_bandwidth>
</edgeCommon>
```
src/bgpls_speaker/service/java/netphony-topology/doc/figures/1wayTest.png

52.3 KiB

src/bgpls_speaker/service/java/netphony-topology/doc/figures/2wayTest.png

53.2 KiB

<!-- Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="TRACE">
<Appenders>
<Console name="trace" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="BGP4Peer" level="trace" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="BGP4Server" level="trace" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="BGP4Parser" level="trace" additivity="false">
<AppenderRef ref="Console"/>
</Logger>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>es.tid.netphony</groupId>
<artifactId>topology</artifactId>
<version>1.4.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Netphony TED and BGP-LS peer</name>
<description>Traffic Engineering Database, BGP-LS peer, Topology Module</description>
<url>http://telefonicaid.github.io/netphony-topology/</url>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
<!-- Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) -->
<!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
<!-- you may not use this file except in compliance with the License. -->
<!-- You may obtain a copy of the License at -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->
</license>
</licenses>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
</dependency>
<!-- Error slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>es.tid.netphony</groupId>
<artifactId>network-protocols</artifactId>
<version>1.4.1</version>
<!-- Next local repo only on docker container -->
<!-- <scope>system</scope>
<systemPath>/protocols/target/network-protocols-1.1-SNAPSHOT.jar</systemPath> -->
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-core</artifactId>
<version>${jgrapht-core-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.metaparadigm</groupId>
<artifactId>json-rpc</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.1.0</version>
</dependency>
<!-- JSON processing: jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>${jackson-datatype-joda-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
</dependency>
<!--GRPC DEPENDENCIES-->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc-protobuf-version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc-protobuf-version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc-stub-version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation-api-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
</dependencies>
<developers>
<developer>
<name>Telefonica I+D</name>
<email>oscar.gonzalezdedios@telefonica.com</email>
<organization>Telefonica I+D</organization>
<organizationUrl>https://www.tid.es</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:telefonicaid/netphony-topology.git</connection>
<developerConnection>scm:git:git@github.com:telefonicaid/netphony-topology.git</developerConnection>
<url>git@github.com:telefonicaid/netphony-topology.git</url>
</scm>
<repositories>
<!--Enables to get SNAPSHOTS-->
<repository>
<id>oss.sonatype.org-snapshot</id>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<!--GRPC plugins + extensions-->
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.9.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.24.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>${basedir}/src/main/sample-config-files</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>eu.teraflow.tid.bgp4Peer.peer.BGPPeerMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>deploy-maven-central</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>bgp-ls-speaker</id>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>4.1.77.Final</version>
<classifier>linux-x86_64</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>bgp-ls-speaker</finalName>
<archive>
<manifest>
<mainClass>eu.teraflow.tid.bgp4Peer.peer.BGPPeerMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-javadoc</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<failOnError>false</failOnError>
</configuration>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>integration-test</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.13</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- No encuentra surefire-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<!-- <shutdown>kill</shutdown> Use it if required-->
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>generate-full-jar</id>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<filters>
<filter>
<artifact>*:*</artifact>
<!-- <excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes> -->
</filter>
</filters>
<minimizeJar>false</minimizeJar>
<transformers>
<!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>eu.teraflow.tid.bgp.bgp4Peer.peer.BGPPeerMain</mainClass>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformer>
</transformers>
</configuration>
</execution>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<jersey-version>1.19.4</jersey-version>
<slf4j-version>2.0.6</slf4j-version>
<junit-version>4.8.1</junit-version>
<servlet-api-version>2.5</servlet-api-version>
<jackson-version>2.4.2</jackson-version>
<jodatime-version>2.3</jodatime-version>
<surefire-version>2.19.1</surefire-version>
<jgrapht-core-version>0.9.1</jgrapht-core-version>
<javax-annotation-api-version>1.3.2</javax-annotation-api-version>
<grpc-stub-version>1.24.0</grpc-stub-version>
<grpc-protobuf-version>1.46.0</grpc-protobuf-version>
<jackson-datatype-joda-version>2.1.5</jackson-datatype-joda-version>
</properties>
</project>
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
import es.tid.bgp.bgp4.messages.BGP4Message;
import es.tid.bgp.bgp4.messages.BGP4MessageTypes;
import es.tid.bgp.bgp4.messages.BGP4Update;
import eu.teraflow.tid.bgp4Peer.peer.BGP4Exception;
import eu.teraflow.tid.bgp4Peer.updateTEDB.UpdateDispatcher;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.util.Timer;
/**
* BGP4 session server
*
* @author mcs
*
*/
public class BGP4PeerInitiatedSession extends GenericBGP4Session{
/**
* Class to dispatch the BGP4 update messages.
* If a BGP5 update message is received, it is stored in a queue of UpdateDispatcher.
*/
private UpdateDispatcher updateDispatcher;
/**
* Constructor of the BGP4 Session
* @param s Socket of the BGP4Peer-BGP4Peer Communication
* @param bgp4SessionsInformation bgp4SessionsInformation
* @param updateDispatcher updateDispatcher
* @param holdTime holdTime
* @param BGPIdentifier BGPIdentifier
* @param version version
* @param myAutonomousSystem myAutonomousSystem
* @param noDelay noDelay
* @param keepAliveTimer keepAliveTimer
*/
public BGP4PeerInitiatedSession(Socket s, BGP4SessionsInformation bgp4SessionsInformation, UpdateDispatcher updateDispatcher,int holdTime,Inet4Address BGPIdentifier,int version,int myAutonomousSystem,boolean noDelay,int keepAliveTimer ){
super(bgp4SessionsInformation, holdTime, BGPIdentifier, version, myAutonomousSystem,keepAliveTimer);
this.setFSMstate(BGP4StateSession.BGP4_STATE_IDLE);
log=LoggerFactory.getLogger("BGP4Server");
log.debug("New BGP4Session: "+s);
this.socket = s;
try {
s.setTcpNoDelay(noDelay);
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.newSessionId();
this.remotePeerIP =(Inet4Address) ((InetSocketAddress) socket.getRemoteSocketAddress()).getAddress();
timer=new Timer();
this.updateDispatcher = updateDispatcher;
//this.keepAliveLocal=params.getKeepAliveTimer();
//this.deadTimerLocal=params.getDeadTimer();
}
/**
* Initiates a Session the BGP-4 Peers
*/
public void run() {
try {
initializeBGP4Session();
} catch (BGP4Exception e2) {
// TODO Auto-generated catch block
try {
this.socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
log.info("BGP4 Session established with peer "+this.remotePeerIP);
this.deadTimerT=new DeadTimerThread(this, this.holdTime);
startDeadTimer();
this.keepAliveT=new KeepAliveThread(out, this.keepAliveTimer);
startKeepAlive();
//Listen to new messages
try{
while(this.FSMstate==BGP4StateSession.BGP4_STATE_SESSION_UP) {
try {
this.msg = readBGP4Msg(in);//Read a new message
}catch (IOException e){
cancelDeadTimer();
cancelKeepAlive();
timer.cancel();
try {
in.close();
out.close();
} catch (Exception e1) {
log.warn("Exception Closing BGP4 Session with "+this.remotePeerIP);
}
log.debug("Finishing BGP4 Session with "+this.remotePeerIP);
return;
}
if (this.msg != null) {//If null, it is not a valid PCEP message
boolean bgp4Msg = true;//By now, we assume a valid PCEP message has arrived
//Depending on the type a different action is performed
switch(BGP4Message.getMessageType(this.msg)) {
case BGP4MessageTypes.MESSAGE_OPEN:
log.debug("OPEN message received");
//After the session has been started, ignore subsequent OPEN messages
log.warn("OPEN message ignored");
break;
case BGP4MessageTypes.MESSAGE_KEEPALIVE:
log.debug("KEEPALIVE message received from "+this.remotePeerIP);
//The Keepalive message allows to reset the deadtimer
break;
case BGP4MessageTypes.MESSAGE_NOTIFICATION:
log.info("NOTIFICATION message from "+this.remotePeerIP);
break;
case BGP4MessageTypes.MESSAGE_UPDATE:
log.debug("UPDATE message from "+this.remotePeerIP);
BGP4Update bgp4Update = new BGP4Update(msg);
log.debug(bgp4Update.toString());
bgp4Update.setLearntFrom(this.getRemotePeerIP().toString());
updateDispatcher.dispatchRequests(bgp4Update);
break;
default:
log.warn("ERROR: unexpected message from "+this.remotePeerIP);
bgp4Msg = false;
}
if (bgp4Msg) {
//Reseting Dead Timer as BGP4 Session Message has arrived
resetDeadTimer();
}
}
}
}finally{
log.error("BGP4 session with peer "+this.remotePeerIP+" has been closed");
cancelDeadTimer();
cancelKeepAlive();
this.FSMstate=BGP4StateSession.BGP4_STATE_IDLE;
endSession();
}
}
@Override
public void close() {
// TODO Auto-generated method stub
}
@Override
protected void endSession() {
// TODO Auto-generated method stub
log.debug("Ending session with id "+this.getSessionId()+" from peer "+this.remotePeerIP);
BGP4SessionsInformation.deleteSession(this.getSessionId());
}
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
import es.tid.bgp.bgp4.messages.BGP4Message;
/**
* BGP Session Interface
*
* @author mcs
*
*/
public interface BGP4Session {
/**
* Send close message and finish the BGP Session
*/
public void close(/*int reason*/);
/**
* Finish the BGP Session abruptly,
*/
public void killSession();
/**
* Encodes and sends BGP Message
* If the message is bad encoded, the session is closed
* @param message BGP4 Message
*/
public void sendBGP4Message(BGP4Message message);
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
import es.tid.bgp.bgp4.messages.BGP4Message;
import es.tid.bgp.bgp4.messages.BGP4MessageTypes;
import es.tid.bgp.bgp4.messages.BGP4Update;
import eu.teraflow.tid.bgp4Peer.peer.BGP4Exception;
import eu.teraflow.tid.bgp4Peer.updateTEDB.UpdateDispatcher;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.Socket;
import java.util.Timer;
/**
* Client session
*
* @author mcs
*
*/
public class BGP4SessionClient extends GenericBGP4Session{
/**
* Peer BGP port to which the session is connected
*/
private int peerBGP_port;
/**
* Delay
*/
private boolean no_delay=true;
private String localBGP4Address;
private int localBGP4Port;
/**
* Class to dispatch the BGP4 update messages.
* If a BGP5 update message is received, it is stored in a queue of UpdateDispatcher.
*/
private UpdateDispatcher updateDispatcher;
public BGP4SessionClient(BGP4SessionsInformation bgp4SessionsInformation,UpdateDispatcher updateDispatcher, Inet4Address peerBGP_IPaddress, int peerBGP_port, int holdTime,Inet4Address BGPIdentifier,int version,int myAutonomousSystem, String localBGP4Address, int localBGP4Port,int keepAliveTimer){
super(bgp4SessionsInformation, holdTime, BGPIdentifier, version, myAutonomousSystem,keepAliveTimer);
timer=new Timer();
log = LoggerFactory.getLogger("BGP4Client");
this.peerBGP_port = peerBGP_port;
this.updateDispatcher=updateDispatcher;
this.localBGP4Address=localBGP4Address;
this.localBGP4Port=localBGP4Port;
this.remotePeerIP = peerBGP_IPaddress;
}
/**
* Initiates a Session between the local BGP Peer and the remote BGP Peer
*/
public void run() {
log.info("Opening new BGP4 Session with host "+ this.remotePeerIP.getHostAddress() + " on port " + this.peerBGP_port);
log.debug("Do we want to update from peer?" + updateFrom);
log.debug("Do we want to send to peer?" + sendTo);
try {
Inet4Address addr = (Inet4Address) Inet4Address.getByName(localBGP4Address);
Inet4Address addrPeer = remotePeerIP;
socket = new Socket(addrPeer, peerBGP_port, addr, 0);
if (no_delay){
this.socket.setTcpNoDelay(true);
log.debug("No delay activated");
}
} catch (IOException e) {
log.info("Connection refused trying to connect " + remotePeerIP.getHostAddress() + " on port " + peerBGP_port);
//As there is not yet a session added (it is added in the beginning of initializeBGP4Session());
//endSession();
return;
}
try {
initializeBGP4Session();
log.info("BGP4 Session established with peer "+this.remotePeerIP);
this.keepAliveT= new KeepAliveThread(this.getOut(),this.keepAliveTimer);
keepAliveT.start();
} catch (BGP4Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
log.debug("Session with "+this.remotePeerIP+" already exists: "+e2.getMessage());
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
log.error("Problem closing socket "+e.getMessage());
}
return;
}
try{
while(this.FSMstate==BGP4StateSession.BGP4_STATE_SESSION_UP) {
try {
this.msg = readBGP4Msg(in);//Read a new message
}catch (IOException e){
cancelDeadTimer();
cancelKeepAlive();
timer.cancel();
try {
in.close();
out.close();
} catch (Exception e1) {
log.warn("problem closing sockets");
}
log.debug("Finishing BGP4 Session abruptly!");
return;
}
if (this.msg != null) {//If null, it is not a valid PCEP message
boolean bgp4Msg = true;//By now, we assume a valid PCEP message has arrived
//Depending on the type a different action is performed
switch(BGP4Message.getMessageType(this.msg)) {
case BGP4MessageTypes.MESSAGE_OPEN:
log.debug("BGP OPEN message received from "+this.remotePeerIP);
//After the session has been started, ignore subsequent OPEN messages
log.warn("OPEN message ignored");
break;
case BGP4MessageTypes.MESSAGE_KEEPALIVE:
log.debug("BGP KEEPALIVE message received from "+this.remotePeerIP);
//The Keepalive message allows to reset the deadtimer
break;
case BGP4MessageTypes.MESSAGE_NOTIFICATION:
log.debug("BGP NOTIFICATION message received from "+this.remotePeerIP);
break;
case BGP4MessageTypes.MESSAGE_UPDATE:
log.debug("BGP UPDATE message received from "+this.remotePeerIP);
if(this.getUpdateFrom()){
BGP4Update bgp4Update = new BGP4Update(msg);
log.debug(bgp4Update.toString());
bgp4Update.setLearntFrom(this.remotePeerIP.getHostAddress() );
updateDispatcher.dispatchRequests(bgp4Update);
}
else
log.debug("Update message from " + this.remotePeerIP + " discarded");
break;
default:
log.warn("ERROR: unexpected message received");
bgp4Msg = false;
}
if (bgp4Msg) {
//Reseting Dead Timer as BGP4 Session Message has arrived
resetDeadTimer();
}
}
}
}finally{
//log.error("SESSION "+ internalSessionID+" IS KILLED");
log.info("BGP4 session with peer "+this.remotePeerIP+" has been closed");
cancelDeadTimer();
cancelKeepAlive();
this.FSMstate=BGP4StateSession.BGP4_STATE_IDLE;
endSession();
}
}
public int getPeerBGP_port() {
return peerBGP_port;
}
public void setPeerBGP_port(int peerBGP_port) {
this.peerBGP_port = peerBGP_port;
}
public Boolean getUpdateFrom() {
return updateFrom;
}
public void setUpdateFrom(Boolean updateFrom) {
this.updateFrom = updateFrom;
}
public Boolean getSendTo() {
return sendTo;
}
public void setSendTo(Boolean sendTo) {
this.sendTo = sendTo;
}
public boolean isNo_delay() {
return no_delay;
}
public void setNo_delay(boolean no_delay) {
this.no_delay = no_delay;
}
@Override
public void close() {
// TODO Auto-generated method stub
}
@Override
protected void endSession() {
// TODO Auto-generated method stub
log.debug("Ending session with id "+this.getSessionId());
this.BGP4SessionsInformation.deleteSession(this.getSessionId());
}
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
public class BGP4SessionExistsException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.teraflow.tid.bgp4Peer.peer.BGP4Exception;
import java.io.DataOutputStream;
import java.net.Inet4Address;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* Class where the oppened BGP4 sessions are stored.
*
* @author mcs
*
*/
public class BGP4SessionsInformation {
public Hashtable<Long,GenericBGP4Session> sessionList;
public Hashtable<Inet4Address,GenericBGP4Session> sessionListByPeerIP;
private boolean isTest = false;
Logger log;
//FIXME: ya lo tenemos a trav�s de la lista de sesiones
DataOutputStream out;
public BGP4SessionsInformation(){
sessionList=new Hashtable<Long,GenericBGP4Session>();
sessionListByPeerIP=new Hashtable<Inet4Address,GenericBGP4Session>();
log = LoggerFactory.getLogger("BGP4Parser");
}
public BGP4SessionsInformation(boolean test){
sessionList=new Hashtable<Long,GenericBGP4Session>();
sessionListByPeerIP=new Hashtable<Inet4Address,GenericBGP4Session>();
log = LoggerFactory.getLogger("BGP4Parser");
isTest= test;
}
public synchronized void notifySessionStart(Inet4Address addr) throws BGP4SessionExistsException{
if (sessionListByPeerIP.containsKey(addr)){
throw new BGP4SessionExistsException();
}
}
public synchronized void addSession(long sessionId, GenericBGP4Session session) throws BGP4Exception{
Enumeration <GenericBGP4Session > sessions = sessionList.elements();
log.debug("Looking to add session with id "+sessionId+" --> "+session.toString());
//Check if there is already a session with the remote peer.
//Only one session allowed with each remote peer
GenericBGP4Session existingSession=sessionListByPeerIP.get(session.remotePeerIP);
if(isTest){
//If there is no existing session with the peer
sessionList.put(new Long(sessionId),session);
sessionListByPeerIP.put(session.getPeerIP() , session);
log.debug("Registering new session with Peer "+session.getPeerIP() +" with ID "+sessionId);
}
else{
if (existingSession!=null){
log.debug("Session with id "+existingSession.getSessionId()+" against "+session.remotePeerIP.getHostAddress()+" already exists");
throw new BGP4Exception();//si no existe throw new BGP4Exception();
}
//If there is no existing session with the peer
sessionList.put(new Long(sessionId),session);
sessionListByPeerIP.put(session.getPeerIP() , session);
log.debug("Registering new session with Peer "+session.getPeerIP() +" with ID "+sessionId);
}
}
public synchronized void deleteSession(long sessionId){
GenericBGP4Session ses=sessionList.get(sessionId);
if (ses!=null) {
Inet4Address ip=sessionList.get(sessionId).getPeerIP();
sessionList.remove(new Long(sessionId));
sessionListByPeerIP.remove(ses.getPeerIP());
log.debug("Deleted Session with id "+sessionId +" with peer "+ses.getPeerIP().getHostAddress());
}else {
log.info("SESSION WAS NOT REGISTERED NULL");
}
}
@Override
public String toString() {
StringBuffer sb=new StringBuffer(2000);
int counter = 1;
Enumeration <GenericBGP4Session > sessions = sessionList.elements();
//Comprobar si ya existe la session con ese peer
while (sessions.hasMoreElements()){
sb.append("Session number "+(counter++)+"\n");
sb.append(sessions.nextElement().toString()+"\n");
}
return sb.toString();
}
public String printSession(long sessionId){
GenericBGP4Session ses=sessionList.get(new Long(sessionId));
if (ses!=null){
return ses.toString();
}else {
return "session "+sessionId+" does not exist";
}
}
public DataOutputStream getOut() {
return out;
}
public void setOut(DataOutputStream out) {
this.out = out;
}
public Hashtable<Long, GenericBGP4Session> getSessionList() {
return sessionList;
}
public void setSessionList(Hashtable<Long, GenericBGP4Session> sessionList) {
this.sessionList = sessionList;
}
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
/**
* The state session attribute indicates the current state of the BGP
FSM
* @author mcs
*
*/
public class BGP4StateSession {
public static final int BGP4_STATE_IDLE=0;
public static final int BGP4_STATE_TCP_PENDING=1;
public static final int BGP4_STATE_OPEN_WAIT=2;
public static final int BGP4_STATE_KEEP_WAIT=3;
public static final int BGP4_STATE_SESSION_UP=4;
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
import java.util.TimerTask;
public class ConnectRetryTimer extends TimerTask {
int initialValue;
ConnectRetryTimer(int initialValue){
this.initialValue=initialValue;
}
@Override
public void run() {
// TODO Auto-generated method stub
}
}
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eu.teraflow.tid.bgp4Peer.bgp4session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* BGP4 DeadTimer management Thread
*
*/
public class DeadTimerThread extends Thread {
private BGP4Session bgp4Session = null;
private int deadTimer = 0;
private Logger log;
private boolean running;
public DeadTimerThread(BGP4Session p, int d) {
this.deadTimer = d;
this.bgp4Session = p;
log=LoggerFactory.getLogger("BGP4Server");
}
public void run() {
running=true;
while (running) {
try {
sleep(deadTimer * 1000);
/*
* Time's over, close PCEP Session
*/
log.warn("DeadTimer OVER");
this.bgp4Session.close(/*ObjectParameters.REASON_DEADTIMER*/);
return;
} catch (InterruptedException e) {
//return;
if (running==false){
log.debug("Ending DeadTimerThread");
return;
}
else {
log.debug("Reseting Dead Timer");
}
} catch (Exception e) {
//FIXME: Ver que hacer aqui, por ahora, solo saco un log
log.warn("Unhandled exception: " + e.getMessage());
}
}
}
public void stopRunning(){
running=false;
}
}