Skip to content

Commit

Permalink
Merge pull request #6639 from TheThingsNetwork/fix/packet-broker-view
Browse files Browse the repository at this point in the history
Simplify Packet Broker settings
  • Loading branch information
ryaplots authored Oct 30, 2023
2 parents c157c28 + 1e87d83 commit 424bb46
Show file tree
Hide file tree
Showing 21 changed files with 795 additions and 445 deletions.
13 changes: 11 additions & 2 deletions cypress/e2e/console/admin-panel/packet-broker/networks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ describe('Packet Broker networks', () => {
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks`,
)
cy.findByLabelText('Use custom routing policies').check()

const { networks } = this.networks
const networksFiltered = networks.filter(
Expand Down Expand Up @@ -73,7 +78,11 @@ describe('Packet Broker networks', () => {
n => n.forwarder_id.net_id === 19 && n.forwarder_id.tenant_id === 'johan',
)

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19/johan`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19/johan`,
)

cy.findAllByText(`${network.id.net_id.toString(16).padStart(6, '0')}/${network.id.tenant_id}`)
cy.findByText(
Expand Down
26 changes: 14 additions & 12 deletions cypress/e2e/console/admin-panel/packet-broker/registration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ describe('Packet Broker registration', () => {
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByText('Packet Broker', { selector: 'h1' }).should('be.visible')
cy.findByText(/Packet Broker can be used to exchange traffic/).should('be.visible')
cy.findByText('Packet Broker documentation', { selector: 'a' }).should('be.visible')
cy.findByText(/Packet Broker is a service by The Things Industries/).should('be.visible')
cy.findByText('Packet Broker', { selector: 'a' }).should('be.visible')
cy.findByText('Packet Broker website', { selector: 'a' }).should('be.visible')
cy.findByText('Register network', { selector: 'span' }).should('be.visible')
cy.findByText('Enable Packet Broker', { selector: 'span' }).should('be.visible')
cy.findByTestId('switch')
.should('be.visible')
.and('not.be.checked')
.and('not.have.attr', 'disabled')
cy.findByText(/To enable peering/).should('be.visible')
cy.findByText(/Enabling will allow/).should('be.visible')

cy.findByText('Default routing policy').should('not.exist')
cy.findByText('Networks').should('not.exist')
Expand All @@ -89,18 +89,20 @@ describe('Packet Broker registration', () => {
cy.loginConsole({ user_id: 'admin', password: 'admin' })
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByText('Register network').click()
cy.findByText('Register network').next().findByTestId('switch').should('be.checked')
cy.findByText('List network publicly')
cy.findByText('Enable Packet Broker').click()
cy.findByText('Enable Packet Broker').next().findByTestId('switch').should('be.checked')
cy.findByText('List my network in Packet Broker publicly')
.should('be.visible')
.next()
.findByTestId('switch')
.should('be.checked')
cy.findByTestId('feature-info-forwarder-enabled').should('be.visible')
cy.findByTestId('feature-info-home-network-enabled').should('be.visible')
cy.findByTestId('tabs').findByText('Default routing policy').should('be.visible')
cy.findByTestId('tabs').findByText('Networks').should('be.visible')
cy.findByLabelText('Do not use a default routing policy for this network').should('be.checked')
cy.findByLabelText('Forward traffic to all networks registered in Packet Broker').should(
'exist',
)
cy.findByLabelText(
'Forward traffic to The Things Stack Sandbox (community network) only',
).should('exist')
cy.findByLabelText('Use custom routing policies').should('exist')

cy.findByTestId('error-notification').should('not.exist')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,63 @@ describe('Packet Broker routing policies', () => {
cy.loginConsole({ user_id: 'admin', password: 'admin' })
})

it('succeeds setting a default routing policy', () => {
it('succeeds setting a "traffic to all networks" routing configuration', () => {
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', { statusCode: 404 })
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19/johan', {})
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText('Use default routing policy for this network').check()
cy.findByLabelText('Forward traffic to all networks registered in Packet Broker').check()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing configuration set')
.should('be.visible')
})

it('succeeds setting a "only ttn" routing configuration', () => {
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', { statusCode: 404 })
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19/johan', {})
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/19/ttn', {})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText(
'Forward traffic to The Things Stack Sandbox (community network) only',
).check()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing configuration set')
.should('be.visible')
})

it('succeeds setting a custom routing configuration with a default routing policy', () => {
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', {
fixture: 'console/packet-broker/default-policy.json',
})
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText('Use custom routing policies').check()

// Check routing policy form checkboxes.
cy.findByText('Uplink')
Expand All @@ -56,30 +107,35 @@ describe('Packet Broker routing policies', () => {
cy.findByLabelText('MAC data').check()
cy.findByLabelText('Application data').check()
})
cy.findByRole('button', { name: 'Save default policy' }).click()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing policy set')
.findByText('Default routing configuration set')
.should('be.visible')
})

it('succeeds unsetting a default routing policy', () => {
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/default', {})
cy.intercept('/api/v3/pba/networks*', { fixture: 'console/packet-broker/networks.json' })
cy.intercept('/api/v3/pba/home-networks/policies*', {
fixture: 'console/packet-broker/policies-home-network.json',
})
cy.intercept('GET', '/api/v3/pba/home-networks/policies/default', {
fixture: 'console/packet-broker/default-policy.json',
fixture: 'console/packet-broker/default-custom-policy.json',
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/default', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker`)

cy.findByLabelText('Do not use a default routing policy for this network').check()
cy.findByRole('button', { name: 'Save default policy' }).click()
cy.findByRole('button', { name: 'Save routing configuration' }).click()

cy.findByTestId('error-notification').should('not.exist')
cy.findByTestId('toast-notification')
.should('be.visible')
.findByText('Default routing policy set')
.findByText('Default routing configuration set')
.should('be.visible')
})

Expand All @@ -93,7 +149,11 @@ describe('Packet Broker routing policies', () => {
})
cy.intercept('PUT', '/api/v3/pba/home-networks/policies/19', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19`,
)

// Check routing policy form checkboxes.
cy.findByLabelText('Use network specific routing policy').check()
Expand Down Expand Up @@ -138,7 +198,11 @@ describe('Packet Broker routing policies', () => {
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19`,
)

cy.findByLabelText('Do not use a routing policy for this network').check()
cy.findByRole('button', { name: 'Save routing policy' }).click()
Expand All @@ -161,7 +225,11 @@ describe('Packet Broker routing policies', () => {
})
cy.intercept('DELETE', '/api/v3/pba/home-networks/policies/19', {})

cy.visit(`${Cypress.config('consoleRootPath')}/admin-panel/packet-broker/networks/19`)
cy.visit(
`${Cypress.config(
'consoleRootPath',
)}/admin-panel/packet-broker/routing-configuration/networks/19`,
)

cy.findByLabelText('Use default routing policy for this network').check()
cy.findByRole('button', { name: 'Save routing policy' }).click()
Expand Down
11 changes: 11 additions & 0 deletions cypress/fixtures/console/packet-broker/default-custom-policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"updated_at": "2021-06-21T12:09:26.810087Z",
"uplink": {
"join_request": true,
"mac_data": false,
"application_data": true,
"signal_quality": false,
"localization": false
},
"downlink": { "join_accept": true, "mac_data": false, "application_data": true }
}
118 changes: 118 additions & 0 deletions pkg/webui/console/components/default-routing-policy-form/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright © 2023 The Things Network Foundation, The Things Industries B.V.
//
// 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.

import React, { useCallback, useState } from 'react'
import { Col, Row } from 'react-grid-system'
import { defineMessages } from 'react-intl'

import Form, { useFormContext } from '@ttn-lw/components/form'
import Checkbox from '@ttn-lw/components/checkbox'
import Radio from '@ttn-lw/components/radio-button'

import Message from '@ttn-lw/lib/components/message'

import sharedMessages from '@ttn-lw/lib/shared-messages'

import policyMessages from '@console/lib/packet-broker/messages'

const m = defineMessages({
doNotUseADefaultPolicy: 'Do not use a default routing policy for this network',
})

const useDefaultEncode = val => val === 'default'
const useDefaultDecode = val => (val ? 'default' : 'no-default')

const DefaultRoutingPolicyForm = () => {
const { values } = useFormContext()
const [useDefault, setUseDefault] = useState(values._use_default_policy || false)
const handlePolicySourceChange = useCallback(setUseDefault, [setUseDefault])

return (
<Row>
<Col md={12}>
<Form.Field
component={Radio.Group}
className="mb-ls-s"
name="_use_default_policy"
onChange={handlePolicySourceChange}
encode={useDefaultEncode}
decode={useDefaultDecode}
>
<Radio label={m.doNotUseADefaultPolicy} value="no-default" />
<Radio label={sharedMessages.useDefaultPolicy} value="default" />
</Form.Field>
</Col>
{useDefault && (
<>
<Col md={6} xs={12}>
<Message content={sharedMessages.uplink} component="h4" className="mb-cs-xs" />
<Form.Field
name="policy.uplink.join_request"
component={Checkbox}
label={policyMessages.joinRequest}
description={policyMessages.joinRequestDesc}
/>
<Form.Field
name="policy.uplink.mac_data"
component={Checkbox}
label={sharedMessages.macData}
description={policyMessages.macDataDesc}
/>
<Form.Field
name="policy.uplink.application_data"
component={Checkbox}
label={sharedMessages.appData}
description={policyMessages.applicationDataDesc}
/>
<Form.Field
name="policy.uplink.signal_quality"
component={Checkbox}
label={policyMessages.signalQualityInformation}
description={policyMessages.signalQualityInformationDesc}
/>
<Form.Field
name="policy.uplink.localization"
component={Checkbox}
label={policyMessages.localizationInformation}
description={policyMessages.localizationInformationDesc}
/>
</Col>
<Col sm={6} xs={12}>
<Message content={sharedMessages.downlink} component="h4" className="mb-cs-xs" />
<Form.Field
name="policy.downlink.join_accept"
component={Checkbox}
label={sharedMessages.joinAccept}
description={policyMessages.joinAcceptDesc}
/>
<Form.Field
name="policy.downlink.mac_data"
component={Checkbox}
label={sharedMessages.macData}
description={policyMessages.macDataAllowDesc}
/>
<Form.Field
name="policy.downlink.application_data"
component={Checkbox}
label={sharedMessages.appData}
description={policyMessages.applicationDataAllowDesc}
/>
</Col>
</>
)}
</Row>
)
}

export default DefaultRoutingPolicyForm
6 changes: 3 additions & 3 deletions pkg/webui/console/components/gateway-visibility-form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ const GatewayVisibilityForm = ({ onSubmit, initialValues, error }) => {
<Form.Field
name="visibility.contact_info"
component={Checkbox}
label={gatewayVisibilityMessages.gatewayContactInfoLabel}
label={sharedMessages.contactInformation}
description={gatewayVisibilityMessages.gatewayContactInfoDescription}
/>
<Form.Field
name="visibility.status"
component={Checkbox}
label={gatewayVisibilityMessages.gatewayStatusLabel}
label={sharedMessages.status}
description={gatewayVisibilityMessages.gatewayStatusDescription}
/>
<Form.Field
name="visibility.frequency_plan"
component={Checkbox}
label={gatewayVisibilityMessages.gatewayFreqPlanLabel}
label={sharedMessages.frequencyPlan}
/>
<Form.Field
name="visibility.packet_rates"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const m = defineMessages({
grpcFieldDescription: 'The address of the service to connect to',
appFormatter: 'Use application payload formatter',
appFormatterWarning: 'This option will affect both uplink and downlink formatter',
setupSubTitle: 'Setup',
defaultFormatter:
'Click <Link>here</Link> to modify the default payload formatter for this application. The payload formatter of this application is currently set to `{defaultFormatter}`',
pasteRepositoryFormatter: 'Paste repository formatter',
Expand Down Expand Up @@ -419,7 +418,7 @@ const PayloadFormattersForm = ({
>
{() => (
<>
<Form.SubTitle title={m.setupSubTitle} />
<Form.SubTitle title={sharedMessages.setup} />
<Form.Field
name={FIELD_NAMES.SELECT}
title={m.formatterType}
Expand Down
Loading

0 comments on commit 424bb46

Please sign in to comment.