Skip to content

Commit

Permalink
Merge pull request #229 from fabric-testbed/al2s
Browse files Browse the repository at this point in the history
add missing plguin.py and change the facility port name to match late…
  • Loading branch information
kthare10 authored Jun 14, 2023
2 parents a6e3684 + 25b2338 commit eb86487
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fabric_examples/beta_functionality/rel1.4/create_al2s.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
"source": [
"from ipaddress import ip_address, IPv4Address, IPv6Address, IPv4Network, IPv6Network\n",
"\n",
"slice_name = 'MySlice-al2s-komal-3'\n",
"site1='RENC'\n",
"slice_name = 'MySlice-al2s-3'\n",
"site1='CERN'\n",
"\n",
"node1_name = 'Node1'\n",
"\n",
Expand Down Expand Up @@ -110,18 +110,18 @@
" net1 = slice.add_l3network(name=network1_name, interfaces=[iface1], type='L3VPN')\n",
"\n",
" # Create a Cloud Facility Port\n",
" fabric_facility_port = slice.add_facility_port(name='Cloud_Facility_AWS', site='AWS',\n",
" fabric_facility_port = slice.add_facility_port(name='Cloud-Facility-AWS', site='AWS',\n",
" # Facility Port can be chosen either by passing region, local_name or device_name, if neither is passed a random Port is returned\n",
" # VLAN can be user specified or can be assigned by ControlFramework if not specified\n",
" \n",
" # Only Specify Port Name\n",
" labels=Labels(vlan='2', ipv4_subnet='192.168.30.1/24', local_name='HundredGigE0/0/0/7'),\n",
" #labels=Labels(vlan='2', ipv4_subnet='192.168.30.1/24', local_name='HundredGigE0/0/0/7'),\n",
" \n",
" # Only specify region\n",
" # labels=Labels(ipv4_subnet='192.168.30.1/24', region='us-east-1'),\n",
" #labels=Labels(ipv4_subnet='192.168.30.1/24', region='us-east-1'),\n",
" \n",
" # Only specify device name\n",
" # labels=Labels(ipv4_subnet='192.168.30.1/24', device_name='agg3.dall3.net.internet2.edu'),\n",
" labels=Labels(ipv4_subnet='192.168.30.1/24', device_name='agg3.dall3.net.internet2.edu'),\n",
" \n",
" # Device and Region Name\n",
" # labels=Labels(ipv4_subnet='192.168.30.1/24', region='us-east-1', device_name='agg4.ashb.net.internet2.edu'),\n",
Expand Down
149 changes: 149 additions & 0 deletions fabric_examples/beta_functionality/rel1.4/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import logging
import time

import ipaddress
from ipaddress import IPv4Network


from fabric_cf.orchestrator.orchestrator_proxy import Status
from fabrictestbed.slice_editor import Labels, Flags, Capacities

from fabrictestbed_extensions.fablib.slice import Slice
from fabrictestbed_extensions.fablib.facility_port import FacilityPort
from fabrictestbed_extensions.fablib.network_service import NetworkService, ServiceType
from typing import List

from fabrictestbed_extensions.fablib.interface import Interface

class Plugins:
@staticmethod
def load():
n = NetworkService
n.network_service_map["PortMirror"] = ServiceType.PortMirror
n.fim_l2network_service_types.append("PortMirror")

n.change_public_ip = Plugins.change_public_ip
n.new_l3network = Plugins.new_l3network
n.new_network_service = Plugins.new_network_service

s = Slice
s.add_facility_port = Plugins.add_facility_port
s.add_l3network = Plugins.add_l3network
f = FacilityPort
f.new_facility_port = Plugins.new_facility_port


def change_public_ip(self, ipv6: list[str] = None, ipv4: list[str] = None):
labels = self.fim_network_service.labels
if labels is None:
labels = Labels()
if self.fim_network_service.type == ServiceType.FABNetv4Ext:
labels = Labels.update(labels, ipv4=ipv4)

elif self.fim_network_service.type == ServiceType.FABNetv6Ext:
labels = Labels.update(labels, ipv6=ipv6)

self.fim_network_service.set_properties(labels=labels)

def add_facility_port(self, name: str = None, site: str = None, labels: Labels = None, peer_labels: Labels = None, capacities: Capacities = None) -> NetworkService:
"""
Adds a new L2 facility port to this slice
:return: a new L2 facility port
:rtype: NetworkService
"""
return FacilityPort.new_facility_port(slice=self, name=name, site=site, labels=labels, peer_labels=peer_labels, capacities=capacities)

@staticmethod
def new_facility_port(
slice: Slice = None, name: str = None, site: str = None,
labels: Labels = None, peer_labels: Labels = None, capacities: Capacities = None):

if capacities is None:
capacities = Capacities(bw=10)

fim_facility_port = slice.get_fim_topology().add_facility(name=name, site=site, capacities=capacities, labels=labels, peer_labels=peer_labels)

return FacilityPort(slice, fim_facility_port)

def add_l3network(
self, name: str = None, interfaces: List[Interface] = [], type: str = "IPv4",
technology: str = None) -> NetworkService:
return NetworkService.new_l3network(
slice=self, name=name, interfaces=interfaces, type=type, technology=technology
)

@staticmethod
def new_l3network(
slice: Slice = None,
name: str = None,
interfaces: List[Interface] = [],
type: str = None, technology: str = None
):
"""
Not inteded for API use. See slice.add_l3network
"""
if type == "IPv6":
nstype = ServiceType.FABNetv6
elif type == "IPv4":
nstype = ServiceType.FABNetv4
elif type == "IPv4Ext":
nstype = ServiceType.FABNetv4Ext
elif type == "IPv6Ext":
nstype = ServiceType.FABNetv6Ext
elif type == "L3VPN":
nstype = ServiceType.L3VPN
else:
raise Exception(
"Invalid L3 Network Type: Allowed values [IPv4, IPv4Ext, IPv6, IPv6Ext, L3VPN]"
)

# TODO: need a fabnet version of this
# validate nstype and interface List
# NetworkService.validate_nstype(nstype, interfaces)

return NetworkService.new_network_service(
slice=slice, name=name, nstype=nstype, interfaces=interfaces, technology=technology
)

@staticmethod
def new_network_service(
slice: Slice = None,
name: str = None,
nstype: ServiceType = None,
interfaces: List[Interface] = [],
user_data: dict = {}, technology: str = None
):
"""
Not intended for API use. See slice.add_l2network
Creates a new FABRIC network service and returns the fablib instance.
:param slice: the fabric slice to build the network service with
:type slice: Slice
:param name: the name of the new network service
:type name: str
:param nstype: the type of network service to create
:type nstype: ServiceType
:param interfaces: a list of interfaces to
:return: the new fablib network service
:rtype: NetworkService
"""
fim_interfaces = []
for interface in interfaces:
fim_interfaces.append(interface.get_fim_interface())

logging.info(
f"Create Network Service: Slice: {slice.get_name()}, Network Name: {name}, Type: {nstype}"
)
fim_network_service = slice.topology.add_network_service(
name=name, nstype=nstype, interfaces=fim_interfaces, technology=technology
)

network_service = NetworkService(
slice=slice, fim_network_service=fim_network_service
)
network_service.set_user_data(user_data)
network_service.init_fablib_data()

return network_service

0 comments on commit eb86487

Please sign in to comment.