2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenStack trunkポート作成手順

Last updated at Posted at 2017-09-17

OpenStackでtrunkポートを使おう

はじめに

OpenStackを触り始めたころインスタンスにvlan I/F持たせたい場合は 適当にvlan I/Fを持たせて Flat NWに繋ぎ込めばいいと思ってました。もちろん駄目でした。

neutronでtrunk portが作れると知った時 Flat NWのportとしてtrunkポートを作成してオプションなりでvlan IDでも指定すればいいんだろうと思いました。
やっぱり勿論駄目でした。

neutron内でのパケットの動きについては別途纏めたいと思いますが 今回はtrunk portの作成並びに使い方を纏めたいと思います。

環境条件

trunk port作成/インスタンス作成のワークフロー

  1. neutronの拡張機能vlanを有効化する

  2. vlan I/Fの親となるNIC用NWの作成 / サブネットワーク作成
    作成するNW種別は何でもOKです。vlan IF用ネットワークと物理ネットワークが別でもOKです。今回はflat NWで作成しました

  3. 使用するvlan毎に VLAN NW作成 / サブネットワーク作成
    こちらもNW種別はvxlanでもvlanでも何でもOKです。ただOpenStack外のサーバと直接tag付きパケットで通信するとかだとvlanにしておくのが無難?
    今回は外部NWなvlan NWとして作成しました。

  4. 親となるport作成

  5. vlan IF用のport作成
    port作成時に親portと同じMACアドレスとして作成しておくのが無難です

  6. trunkを作成し 親portとvlan IF用portを紐づけ

  7. インスタンスの作成(親portを選択、vlan IFは選択する必要なし)

設定手順

実際に作成してみました。

  • neutron-serverが動作しているノードでservice_pluginにtrunkを追加
# vi /etc/neutron/neutron.conf

[DEFAULT]
service_plugins=router,metering,trunk
  • neutron-server再起動
# systemctl restart neutron-server
  • 拡張機能でtrunkが有効化されていることを確認
# openstack extension list --network|grep trunk
| Trunk port details                                          | trunk-details             | Expose trunk port details       
| Trunk Extension                                             | trunk                     | Provides support for trunk ports
  • trunkの親ポートのためのNWを作成
# openstack network create --external --project admin --provider-network-type flat --provider-physical-network flat-net flat
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2017-09-17T05:47:58Z                 |
| description               |                                      |
| dns_domain                | None                                 |
| id                        | 321728f5-2b92-4b1a-a0c9-7713ea28b0b4 |
| ipv4_address_scope        | None                                 |
| ipv6_address_scope        | None                                 |
| is_default                | False                                |
| mtu                       | 1500                                 |
| name                      | flat                                 |
| port_security_enabled     | True                                 |
| project_id                | c04821c34fc240ffb5f65ef047151174     |
| provider:network_type     | flat                                 |
| provider:physical_network | flat-net                             |
| provider:segmentation_id  | None                                 |
| qos_policy_id             | None                                 |
| revision_number           | 4                                    |
| router:external           | External                             |
| segments                  | None                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| updated_at                | 2017-09-17T05:47:58Z                 |
+---------------------------+--------------------------------------+
#
  • サブネットワーク作成
openstack subnet create --subnet-range 192.168.1.0/24 --gateway 192.168.1.1 --network flat flatsubnet
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 192.168.1.2-192.168.1.254            |
| cidr              | 192.168.1.0/24                       |
| created_at        | 2017-09-17T05:48:06Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 192.168.1.1                          |
| host_routes       |                                      |
| id                | 6e6b866e-cbbe-4b16-8313-d4b0ed0b21e5 |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | flatsubnet                           |
| network_id        | 321728f5-2b92-4b1a-a0c9-7713ea28b0b4 |
| project_id        | c04821c34fc240ffb5f65ef047151174     |
| revision_number   | 2                                    |
| segment_id        | None                                 |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| updated_at        | 2017-09-17T05:48:06Z                 |
+-------------------+--------------------------------------+
#
  • vlan I/F用ネットワーク作成
# openstack network create --external --project admin --provider-network-type vlan --provider-physical-network provider --provider-segment 10 vlan10
+---------------------------+--------------------------------------+
| Field                     | Value                                |
+---------------------------+--------------------------------------+
| admin_state_up            | UP                                   |
| availability_zone_hints   |                                      |
| availability_zones        |                                      |
| created_at                | 2017-09-17T05:48:15Z                 |
| description               |                                      |
| dns_domain                | None                                 |
| id                        | 37de42e0-77eb-4911-9517-75c6eff76f74 |
| ipv4_address_scope        | None                                 |
| ipv6_address_scope        | None                                 |
| is_default                | False                                |
| mtu                       | 1500                                 |
| name                      | vlan10                               |
| port_security_enabled     | True                                 |
| project_id                | c04821c34fc240ffb5f65ef047151174     |
| provider:network_type     | vlan                                 |
| provider:physical_network | provider                             |
| provider:segmentation_id  | 10                                   |
| qos_policy_id             | None                                 |
| revision_number           | 4                                    |
| router:external           | External                             |
| segments                  | None                                 |
| shared                    | False                                |
| status                    | ACTIVE                               |
| subnets                   |                                      |
| updated_at                | 2017-09-17T05:48:15Z                 |
+---------------------------+--------------------------------------+
#
  • vlan I/F用NWのサブネット作成
# openstack subnet create --subnet-range 192.168.10.0/24 --gateway 192.168.10.1 --network vlan10 vlan10subnet
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 192.168.10.2-192.168.10.254          |
| cidr              | 192.168.10.0/24                      |
| created_at        | 2017-09-17T05:48:23Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 192.168.10.1                         |
| host_routes       |                                      |
| id                | db2a3808-9916-4efc-9cba-0262ce7e6e6f |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | vlan10subnet                         |
| network_id        | 37de42e0-77eb-4911-9517-75c6eff76f74 |
| project_id        | c04821c34fc240ffb5f65ef047151174     |
| revision_number   | 2                                    |
| segment_id        | None                                 |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| updated_at        | 2017-09-17T05:48:23Z                 |
+-------------------+--------------------------------------+
#
  • 親ポート作成
# openstack port create --network flat p-port01
+-----------------------+-----------------------------------------------------------------------------+
| Field                 | Value                                                                       |
+-----------------------+-----------------------------------------------------------------------------+
| admin_state_up        | UP                                                                          |
| allowed_address_pairs |                                                                             |
| binding_host_id       |                                                                             |
| binding_profile       |                                                                             |
| binding_vif_details   |                                                                             |
| binding_vif_type      | unbound                                                                     |
| binding_vnic_type     | normal                                                                      |
| created_at            | 2017-09-17T05:49:36Z                                                        |
| description           |                                                                             |
| device_id             |                                                                             |
| device_owner          |                                                                             |
| dns_assignment        | None                                                                        |
| dns_name              | None                                                                        |
| extra_dhcp_opts       |                                                                             |
| fixed_ips             | ip_address='192.168.1.12', subnet_id='6e6b866e-cbbe-4b16-8313-d4b0ed0b21e5' |
| id                    | c3aad133-9ac2-4aaf-a551-d0dc54f8ae67                                        |
| ip_address            | None                                                                        |
| mac_address           | fa:16:3e:41:bb:e3                                                           |
| name                  | p-port01                                                                    |
| network_id            | 321728f5-2b92-4b1a-a0c9-7713ea28b0b4                                        |
| option_name           | None                                                                        |
| option_value          | None                                                                        |
| port_security_enabled | True                                                                        |
| project_id            | c04821c34fc240ffb5f65ef047151174                                            |
| qos_policy_id         | None                                                                        |
| revision_number       | 5                                                                           |
| security_groups       | d6871fb5-9bcc-44eb-ad75-2ab103759475                                        |
| status                | DOWN                                                                        |
| subnet_id             | None                                                                        |
| updated_at            | 2017-09-17T05:49:37Z                                                        |
+-----------------------+-----------------------------------------------------------------------------+
#
  • vlan I/F用サブポート作成
     mac-addressオプションで親ポートのmacアドレスを指定して作成すること
# openstack port create --network vlan10 --mac-address fa:16:3e:41:bb:e3 vlan10-subport01
+-----------------------+------------------------------------------------------------------------------+
| Field                 | Value                                                                        |
+-----------------------+------------------------------------------------------------------------------+
| admin_state_up        | UP                                                                           |
| allowed_address_pairs |                                                                              |
| binding_host_id       |                                                                              |
| binding_profile       |                                                                              |
| binding_vif_details   |                                                                              |
| binding_vif_type      | unbound                                                                      |
| binding_vnic_type     | normal                                                                       |
| created_at            | 2017-09-17T05:50:19Z                                                         |
| description           |                                                                              |
| device_id             |                                                                              |
| device_owner          |                                                                              |
| dns_assignment        | None                                                                         |
| dns_name              | None                                                                         |
| extra_dhcp_opts       |                                                                              |
| fixed_ips             | ip_address='192.168.10.10', subnet_id='db2a3808-9916-4efc-9cba-0262ce7e6e6f' |
| id                    | 1510d17d-c8e8-49a4-a90b-8fbc2ae82893                                         |
| ip_address            | None                                                                         |
| mac_address           | fa:16:3e:41:bb:e3                                                            |
| name                  | vlan10-subport01                                                             |
| network_id            | 37de42e0-77eb-4911-9517-75c6eff76f74                                         |
| option_name           | None                                                                         |
| option_value          | None                                                                         |
| port_security_enabled | True                                                                         |
| project_id            | c04821c34fc240ffb5f65ef047151174                                             |
| qos_policy_id         | None                                                                         |
| revision_number       | 5                                                                            |
| security_groups       | d6871fb5-9bcc-44eb-ad75-2ab103759475                                         |
| status                | DOWN                                                                         |
| subnet_id             | None                                                                         |
| updated_at            | 2017-09-17T05:50:19Z                                                         |
+-----------------------+------------------------------------------------------------------------------+
#
  • trunk作成
# openstack network trunk create --parent-port p-port01 --subport port=vlan10-subport01,segmentation-type=vlan,segmentation-id=10 trunk01
+-----------------+------------------------------------------------------------------------------------------------+
| Field           | Value                                                                                          |
+-----------------+------------------------------------------------------------------------------------------------+
| admin_state_up  | UP                                                                                             |
| created_at      | 2017-09-17T05:50:37Z                                                                           |
| description     |                                                                                                |
| id              | b7ac37d2-53c1-4dda-a52c-3941677e5a0a                                                           |
| name            | trunk01                                                                                        |
| port_id         | c3aad133-9ac2-4aaf-a551-d0dc54f8ae67                                                           |
| project_id      | c04821c34fc240ffb5f65ef047151174                                                               |
| revision_number | 1                                                                                              |
| status          | DOWN                                                                                           |
| sub_ports       | port_id='1510d17d-c8e8-49a4-a90b-8fbc2ae82893', segmentation_id='10', segmentation_type='vlan' |
| tenant_id       | c04821c34fc240ffb5f65ef047151174                                                               |
| updated_at      | 2017-09-17T05:50:37Z                                                                           |
+-----------------+------------------------------------------------------------------------------------------------+
#
  • インスタンス作成
    horizonから作成してしまったので省略。NWの選択は親のportを割り当ててください。

疎通確認

今回はubuntu16.04のcloud imageを使用してインスタンスを作成し、OpenStackの外に立ててあるubuntuサーバ(192.168.10.200)との疎通を確認しました。

インスタンス上での作業
vlan有効化実施

root@xenial:~# modprobe 8021q
root@xenial:~# lsmod|grep 8021q
8021q                  32768  0
garp                   16384  1 8021q
mrp                    20480  1 8021q
root@xenial:~#

vlan I/F作成,アドレス付与 & ping確認

root@xenial:~# vconfig add ens3 10
Added VLAN with VID == 10 to IF -:ens3:-
root@xenial:~# 
root@xenial:~# more /proc/net/vlan/config
VLAN Dev name    | VLAN ID
Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
ens3.10        | 10  | ens3
root@xenial:~# 
root@xenial:~# ifconfig ens3.10 192.168.10.10/24 up
root@xenial:~#
root@xenial:~# ip ad
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:41:bb:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.12/24 brd 192.168.1.255 scope global ens3
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe41:bbe3/64 scope link
       valid_lft forever preferred_lft forever
3: ens3.10@ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether fa:16:3e:41:bb:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.10/24 brd 192.168.10.255 scope global ens3.10
       valid_lft forever preferred_lft forever
    inet6 fe80::f816:3eff:fe41:bbe3/64 scope link
       valid_lft forever preferred_lft forever
root@xenial:~#
root@xenial:~# ping 192.168.10.200
PING 192.168.10.200 (192.168.10.200) 56(84) bytes of data.
64 bytes from 192.168.10.200: icmp_seq=1 ttl=64 time=6.84 ms
64 bytes from 192.168.10.200: icmp_seq=2 ttl=64 time=1.04 ms
64 bytes from 192.168.10.200: icmp_seq=3 ttl=64 time=1.09 ms
^C
--- 192.168.10.200 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 1.045/2.995/6.847/2.724 ms
root@xenial:~#

無事外部サーバとtag付きパケットで直接通信できました。
ovsのフローエントリーを追うと パケットがどう処理されているか納得できるので自分の整理のためにも今後まとめたいと思います。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?